Endorphins are classified as "endogenous opioid polypeptides" and they are thought to be produced by the pituitary gland and hypothalamus during strenuous exercise, and in response to pain, excitement and other stress stimulus. Once produced, endorphins are distributed throughout the nervous system where they interact with the opiate receptors to reduce our perception of pain. These natural pain relievers not only reduce the perception of pain, but they are also linked with an increased sense of euphoria and well-being.
Also see: The Runner's High
Boecker, H., Sprenger, T., Spilker, M.E., Henriksen, G., Koppenhoefer, M., Wagner, K.J., Valet, M., Berthele, A., Tolle, T.R. (2008). The Runner's High: Opioidergic Mechanisms in the Human Brain. Cerebral Cortex DOI: 10.1093/cercor/bhn013