First off, we know that running isn't the only exercise that can cause a borderline euphoric experience. An extended period of any moderately intense cardio exercise—swimming, biking, etc.—has the potential to do so.
"What everyone agrees on at this point is that exercise has the ability to change your mood because it has a dramatic impact on your brain," Art Kramer, Ph.D., a professor of psychology and director of the Center for Cognitive and Brain Health at Northeastern University, previously told mbg.
As for how exercise changes the brain, neuroscientists looked into it in a 2008 study on 10 male endurance runners. They took two PET scans of each athlete's brains—both at rest and 30 minutes after a two-hour run—and compared the results. They found that running seemed to release endorphins in the frontolimbic area of the brain, which is involved in regulating mood. This explained why the runners' self-reported levels of "euphoria" and "happiness" also shot up after the long run.
Another 2011 study, this one conducted on mice, studied the long-term impact of running on mental health: The University of Colorado team found that consistent, prolonged bouts of wheel running seemed to improve neuroplasticity and alter the reward networks of the brain when done over the course of six weeks, but not two weeks. This could help explain why seasoned runners (of the human variety) seem to get more joy from the exercise than beginners do. It's a high that takes time to build.