4. Given three distinct points $Z_{1}, Z_{2}, Z_{3}$ in the complex plane corresponding to the complex numbers $z_{1}, z_{2}, z_{3}$. If $\left(z_{2}-z_{1}\right)^{2}+\left(z_{3}-z_{1}\right)^{2}=0$, then $\triangle Z_{1} Z_{2} Z_{3}$ is ( ).
(A) an equilateral triangle
(B) an isosceles right triangle
(C) a right triangle, but not necessarily an isosceles triangle
(D) an isosceles triangle, but not necessarily an equilateral triangle
4.B.

From the given equation, we get $z_{2}-z_{1}= \pm \mathrm{i}\left(z_{3}-z_{1}\right)$. Therefore, $Z_{1} Z_{2}=Z_{1} Z_{3}$, and $Z_{1} Z_{2} \perp Z_{1} Z_{3}$.