Endorphins are naturally occurring amino acids. Their function is to reduce sensitivity to pain. They do this by attaching to the receptors in the brain and spinal cord and stop the transfer of pain signals.
In this regard they can be considered to be naturally generated opiates that dull our sensitivity to pain. Physical exercise stimulates the production of endorphins. They have been linked to stress-related infertility problems.