Let $\alpha_1,...,\alpha_n$ be all the complex roots of $f$. Since $f$ is irreducible we know it is separable, so all the roots are distinct. Now let $D=\prod_{i<j}(\alpha_i-\alpha_j)$. The discriminant of $f$ is exactly $D^2$. Now, let $\sigma$ be any permutation in the Galois group of $f$. It defines an automorphism on $\mathbb{Q}(\alpha_1,...,\alpha_n)$, and it satisfies:
$\sigma.D=\operatorname{sgn}(\sigma)\times D$
This follows exactly from the definition of sign of a permutation. Hence $\sigma.D=D$ if and only if $\sigma\in A_n\cap \operatorname{Gal}(\mathbb{Q}(\alpha_1,...,\alpha_n)/\mathbb{Q})$. From here the result easily follows. If $D\in\mathbb{Q}$ then any permutation in the Galois group must fix it, hence all such permutations are in $A_n$. The other direction: Assume $\operatorname{Gal}(\mathbb{Q}(\alpha_1,...,\alpha_n)/\mathbb{Q})\leq A_n$. Then every permutation in $\operatorname{Gal}(\mathbb{Q}(\alpha_1,...,\alpha_n)/\mathbb{Q})$ fixes $D$, hence $D$ belongs to the fixed field of $\operatorname{Gal}(\mathbb{Q}(\alpha_1,...,\alpha_n)/\mathbb{Q})$ which is $\mathbb{Q}$.