The positive effects exercise has on conditions such as anxiety and depression have been studied since the 1980s. The euphoria that follows acute exercise, known as 'runner's high', was discovered by Kenneth Cooper of the Cooper Institute, who cited the case of a man 'who was so despondent, he wanted to die. Because his heart was weak, he thought the best way to commit suicide without embarrassing his family was to run around the block as fast as he could until he killed himself. After several futile attempts at causing a fatal heart attack, he discovered that he began to feel better and eventually chose to live instead.'
The phenomenon is caused by the release of endorphins in the brain, but it's unclear if they promote long-term mental wellbeing. Other research identifies serotonin and norepinephrine - also elevated by exercise - as mechanisms for improved mood. Many antidepressants increase the brain's levels of these neurotransmitters, so it seems reasonable to assume that this is how exercise improves mental wellbeing.