Under the Zariski topology, this is true by basic Algebraic Geometry. However, I was wondering about how to prove this for the metric topology on $\mathbb{C}$. In Algebraic Curves and Riemann Surfaces by Miranda, this is stated as a fact, with a reference to Shafarevich (without giving page number). However, I can't quite see any obvious way to prove this.
More formally, we let $f(z,w)\in\mathbb{C}[z,w]$ be an irreducible polynomial, and we define $X=\{(z,w)\in\mathbb{C}^2\mid f(z,w)=0\}$, and give $X\subset\mathbb{C}^2$ the subspace topology. I wish to prove that given disjoint closed sets $X_1$ and $X_2$ s.t. $X=X_1\cup X_2$, either $X_1=\emptyset$ or $X_2=\emptyset$. I'm struggling to find the connection between the Zariski topology and the metric topology.
I will simply work with the Zariski compactification of $X$ in the projective plane without mentioning it again. When projecting in a moment, if you choose a point at infinity to project from and then remove the image point of that line, you can keep visualizing the affine $X$ if you prefer.
By projecting from a point outside of $X$ we get a map $h: X \to \mathbb{P}^1$. Let $B \subset \mathbb{P}^1$ be the finite set of points for which $h$ is ramified (this includes points over which hypothetical components of $X$ may intersect). Let $U = X \setminus h^{-1}(B)$ and $V = \mathbb{P}^1 \setminus B$. Let me continue to denote by $h$ the map $U \to V$.
Hurwitz theory says that every component (in the Euclidean topology) of $U$ admits in a unique way an algebraic structure for which $h$ is holomorphic. (Uniqueness is actually very easy to see, since $h$ is a local diffeomorphism there is only one complex structure you can use, the one pulled back from $\mathbb{P}^1$). Moreover, these components can be compactified to smooth Riemann surfaces.
Note that if the affine part of $X$ disconnects in the euclidean topology then so does $U$. So assuming that this affine part disconnects let us continue.
Let $U_i$ be distinct components of $U$ with $i=1,2$. Let $Y_i$ be the corresponding compactifications. Then we have rational maps $r_i :Y_i \to X$ induced from the inclusion $U_i \to X$. Any rational map from a smoot Riemann surface to a projective curve extends to a regular map, so $r_i$'s are regular maps (i.e., algebraic and defined everywhere).
Hence, the images of these curves are (algebraic) components of $X$ which means $X$ is reducible as an algebraic variety. This contradicts the fact that $f$ is irreducible. So $X$ must be connected in the euclidean topology.