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 A^n, having a prime ideal I(Y) in the polynomial ring over n variables A. The proof goes as follows:

Let p be a prime ideal, and suppose Z(p) = Y1 union Y2. Then p = I(Y1) intersection I(Y2). Then (here is where I am confused!) p equals I(Y1) or I(Y2). Then of course Y equals Y1 or Y2, thus Y is irreducible.