Near the junction positive charge is built on n-side and negative charge on P-side. This sets up potential difference across the junction and internal electric field Ei directed from n-side to P-side. The equilibrium is established when the field Ei becomes strong enough to stop further diffusion of the majority charge carriers.