Step 1: Understanding the Concept
When a p-n junction forms, electrons diffuse from the n-side to the p-side and holes diffuse the other way. They recombine near the junction.
Step 2: Charges left behind
This leaves fixed positive donor ions on the n-side and fixed negative acceptor ions on the p-side, forming the depletion layer.
Step 3: Result
These two layers of fixed charge create an electric field across the junction. This field opposes further diffusion and acts as the potential barrier.
Final Answer:
The barrier is due to accumulation of positive and negative charges near the junction, which is option (D).
\[ \boxed{\text{(D) }\text{accumulation of positive and negative charges near the junction}} \]