Why $f$ is an automorphism?

Let $G$ be a group and $f: G\rightarrow G$ is a function such that for any $x,y\in G$ we have $$f(xf(y))=f(x)y.$$ Then prove that $f$ is an automorphism of $G$.


By setting $x=1$ we see that $f\circ f$ is the map $y\mapsto f(1)y$, which is bijective. Therefore $f$ is also bijective.

From $f(f(1))=f(1)$ and injectiveness we have $f(1)=1$. It follows that $f\circ f$ is the identity map (in other words, $f=f^{-1}$). It remains to be shown that $f$ is a homomorphism.

For all $a,b\in G$, $f(ab)=f(af(f(b)))=f(a)f(b)$.