At a time when the United States is facing an opioid epidemic, medical marijuana is now legal in 25 states and the District of Columbia. So, how are these two trends related? The connection may surprise you.

A new study from Columbia University's Mailman School of Public Health has found that fewer people are using opioids in states that have legalized medical marijuana.

"In theory, we would expect the adverse consequences of opioid use to decrease over time in states where medical marijuana use is legal, as individuals substitute marijuana for opioids in the treatment of severe or chronic pain," June H. Kim, a doctoral student at the Mailman School of Public Health, and the study's lead author, said in a press release.

Researchers examined federal crash data in 18 states over the period from 1999 to 2013. The results showed that states with legal weed during this period saw an overall reduction in opioid involvement in fatal car accidents, especially among drivers ages 21 to 40.

For example, Montana experienced a 1.7 percent reduction in the number of people who tested positive for opioids after its medical marijuana law went into effect, which was voted into law in 2004. At one point, the state, with a population of about one million, had almost 30,000 patients and 4,900 legal weed providers, according to NBC News.

Fatalities related to opioids are rising drastically — in 2014, about 18,893 overdose deaths in the U.S. were related to prescription painkillers, and 10,574 deaths were related to heroin, the American Society of Addiction Medicine reported.

A recent study also reported that prescription opioid overdose, abuse, and dependence in the U.S. has cost an estimated $78.5 billion.

Read more:

Health Benefits Of Medical Marijuana: 3 Major Ways Cannabis Helps Sick People Live Normal Lives

The Price Of Painkiller Addiction: US Opioid Epidemic Has Cost An Estimated $78.5 Billion