# If an algebraic set in affine n-space has a prime ideal then it is irreducible. (Hartshorne's Algebraic Geometry, Cor. 1.4)

I am confused about a step in Hartshorne's proof (final part of Corollary 1.4) that an algebraic set $Y$ in affine n-space $\mathbb{A}^n$ having a prime ideal $I(Y)$ in the polynomial ring over $n$ variables $A$. The proof goes as follows:

Let $\mathfrak{p}$ be a prime ideal, and suppose $Z(p) = Y_1 \cup Y_2$. Then $p = I(Y_1)$ intersection $I(Y_2)$. Then (here is where I am confused!) $\mathfrak{p}$ equals $I(Y_1)$ or $I(Y_2)$. Then of course $Y$ equals $Y_1$ or $Y_2$, thus $Y$ is irreducible.

If $P=I\cap J$ is prime, and if $P$ is not equal to $I$ or $J$, then choose $i\in I\setminus J$ and $j\in J\setminus I$. Then $ij\in P$, so $i\in P$ or $j\in P$. Contradiction either way. Thus $P=I$ or $P=J$.