Definition
The amazing p-n junction is created when you take a piece of n-type semiconductor and a piece of p-type semiconductor and join them together... in a junction... hence the name p-n junction. (Hey, nobody ever claimed that we engineering types were creative)

P-n junctions allow current to flow in only one direction because of the depletion region and adjusting of energy levels due to their corresponding band gaps and fermi-levels. Checkout the following diagrams, then the brief explanation of the many things happening. There is necessary background information at band gap, semiconductor, and n-type semiconductor.


Diagram
Before joining p-type and n-type semiconductors notice the dotted line fermi levels, a direct result of the dopant that is causing the semiconductors to be either n or p type.

          conduction band
     -----------+  +------------
                |  |- - - - - -
       p-type   |  |  n-type
      - - - - - |  |
     -----------+  +------------
            valence band
After joining them to create a junction we can see that the fermi-level has aligned and now the electrons in the n-region have a potential hill to get up to go over to the other side. The same thing applies to holes on the bottom left hand side, but they are not shown for simplicity's sake. Note the creation of a depletion region. This is an area in which there is a lack of the majority carriers (electrons on the n-side and holes on the p-side).
      ---------+-.
               |  \    O  O  O
        p-type |   '-+----------
      - - - - -|- - -|- - - - -
      ---------+-.   | n-type
                  \  |
                   '-+----------

               |-> <-|
              depletion
               region


Explanation
Electrons freely gather in the conduction band on the side with the n-type semiconductor because they are the majority carrier on the n-side. These electrons can diffuse over to the p-type, through the depletion region. Similarly, holes in the valence band of the p-type semiconductor (in the p-type area holes are the majority carrier) diffuse into the depletion region.

The depletion region has a lack of majority carriers, but the fixed ions from the lattice structure cause a built in electric field to develop across the depletion region. This electric field happens to balance out with the diffusion of carriers in the depletion region to create a net current of zero with no applied voltage.

Applying voltage to the junction, in a forward bias (opposite the built in electric field), allows the electrons from the n-side to more easily travel to the p-side and the holes on the p-side to more easily travel over to the n-side. Keep in mind that holes have positive charge and electrons negative charge, so they will both go in different directions with an applied field. Applying a voltage to the junction, in a reverse bias (adding to the built in electric field), will make it harder for electrons to move across the depletion region, thereby eliminating current.


Conclusion
Because of all this diffusion and depletion region stuff, applying "positive" voltage will cause a lot of current to flow, however applying a negative voltage will result in zero current. Which is what makes p-n junctions useful. Now you can checkout bigger better solid state electronic devices such as the Schottky diode, field effect transistors (MOSFET, JFET, etc), and Bipolar Junction Transistors.




References & Background Information
P-N Junction Basics :
http://www.st-and.ac.uk/~www_pa/Scots_Guide/info/comp/passive/diode/pn_junc/pn_junc.htm

Diagram of Junction :
http://www.acsu.buffalo.edu/~wie/applet/pnformation/pnformation.html

Diagram of Current Flow :
http://www.acsu.buffalo.edu/~wie/applet/students/jiawang/pn.html

Brittany Spears Guide to Semiconductor Physics :
http://britneyspears.ac/lasers.htm

History of the Transistor
http://www.pbs.org/transistor/



This wu really requires background knowledge in physics and some basic solid state fundamentals. I will gladly edit anything to more clearly explain what was going on. Feedback, positive or negative, is always encouraged.