Erection is the scientific term for that state of the penis when the two corpora cavernosa (two tubular muscles) are filled with blood. This means that the penis hardens and grows in length to accommodate the extra blood.
Penile erection is usually the result of sexual stimulation, but is also known to occur spontaneously, most commonly at night, during erotic dreams. Erection in males can be caused by mechanical stimulation, or by the pressure of the bladder, when full. The exact cause of spontaneous erections is not known. The erection is crucial to sexual intercourse and most other sexual activities for males.
From the physiological point of view, erection is caused by an increased flow of blood to the penis and by a strong decrease in the outflow. Muscles around the penis relax in order to allow the blood into the corpora cavernosa and corpus spongiosum, while contraction of other muscles reduces the outflow. As the tubular structures fill with blood, the penis expands in both length and girth. It also stiffens and rises to a certain angle (which varies from one man to another).
The sympathetic nervous system is responsible for the failure to achieve erection under conditions of stress. This system interferes with the signals sent by the parasympathetic nervous system, which is actually responsible for activating the erections.
The inability to achieve or maintain erection is known as impotence, or erectile dysfunction.
A less known fact is that erections can occur even after death, due to increased pressure in the penis from sinking fluids or the accumulation of gases.