9. (16 points) Given the function
$$
f(x)=a x^{2}+b x+c(a \neq 0) \text {, }
$$
$g(x)$ is a quadratic function, and it always holds that
$$
f(g(x))=g(f(x)) .
$$

Find $g(x)$.
9. Let $g(x)=p x^{2}+q x+r(p \neq 0)$.
From $f(g(x))=g(f(x))$, we get
$$
\begin{array}{l}
a\left(p x^{2}+q x+r\right)^{2}+b\left(p x^{2}+q x+r\right)+c \\
=p\left(a x^{2}+b x+c\right)^{2}+q\left(a x^{2}+b x+c\right)+r .
\end{array}
$$

Notice that, $a p \neq 0$.
By comparing the coefficients of $x^{4}$, $x^{3}$, and $x^{2}$, we get
$$
\begin{array}{l}
a p^{2}=p a^{2}, \\
2 a p q=2 p a b, \\
2 a r p+a q^{2}+b p=2 p a c+p b^{2}+a q .
\end{array}
$$

Solving these equations simultaneously, we get $p=a$, $q=b$, $r=c$.
Thus, $g(x)=f(x)$.
Upon verification, it satisfies the requirements.