6. If the positive real numbers $a, b$ satisfy $a b=a+b+3$, then the minimum value of $a^{2}+b^{2}$ is ( ).
(A) -7
(B) 0
(C) 9
(D) 18
6. D.

Let $a+b=m$, then $ab=m+3$, and $m>0$. Therefore, $a, b$ are the roots of the equation $x^{2}-mx+m+3=0$, which gives us
$$
\Delta=m^{2}-4m-12=(m-6)(m+2) \geqslant 0 .
$$

Since $m>0$, we have $m-6 \geqslant 0, m \geqslant 6$. Thus,
$$
\begin{array}{l}
a^{2}+b^{2}=(a+b)^{2}-2ab \\
=m^{2}-2m-6=(m-1)^{2}-7 \geqslant 18 .
\end{array}
$$