For any real numbers $a, b$, construct the algebraic expression
$$
M=a^{2}+a b+b^{2}-a-b+\frac{1}{2} \text {. }
$$

Then the minimum value of $M$ is ( ).
(A) $\frac{1}{2}$
(B) $\frac{1}{3}$
(C) $\frac{1}{6}$
(D) 0
5.C.

With $a$ as the main element, we complete the square to get
$$
\begin{array}{l}
M=a^{2}+(b-1) a+b^{2}-b+\frac{1}{2} \\
=a^{2}+2 \cdot \frac{b-1}{2} \cdot a+\frac{(b-1)^{2}}{4}+\frac{3 b^{2}-2 b+1}{4} \\
=\left(a+\frac{b-1}{2}\right)^{2}+\frac{3}{4}\left(b-\frac{1}{3}\right)^{2}+\frac{1}{6} \geqslant \frac{1}{6} .
\end{array}
$$

When $b=\frac{1}{3}, a=\frac{1}{3}$, $M$ attains its minimum value $\frac{1}{6}$.
Note: The method of completing the square is not unique, such as
$$
M=\frac{(a-b)^{2}}{4}+\frac{3}{4}\left(a+b-\frac{2}{3}\right)^{2}+\frac{1}{6}
$$

etc. However, from the completion of the square
$$
M=\frac{1}{2}\left[(a+b-1)^{2}+a^{2}+b^{2}\right] \geqslant 0
$$

we cannot conclude that the minimum value of $M$ is 0, because the three non-negative terms cannot be zero simultaneously (we can only get $M>0$).