The axiom of extensionality establishes that "if two sets have the same elements, then they are identical", but not the second implication (the one I will use to prove that two sets are equal).
If we try to solve this by defining "A and B are equal sets iff they have the same elements", then why do we need to establish the axiom of extensionality?
The second implication is true without the axiom of extensionality.
To see why, given two sets $A,B$ suppose that $A=B$. It follows that the truth value of a sentence involving $A$ is unchanged when $A$ is substituted by $B$. Apply this to the evidently true statement
by substituting $B$ in place of the second $A$, and we obtain the true statement
This sentence says that $A$ and $B$ have the same elements.