If alcohol is a part of your weekly routine, you should make sure to find time to hit the gym: A new study from the United Kingdom suggests that regular exercise can help balance out the harmful effects of alcohol.

People in the study who drank alcohol — but also exercised on a regular basis — were less likely to die from any cause during the study period, compared with those who drank but didn't exercise.

And exercise had a particularly strong effect on drinkers' risk of dying from cancer. Alcohol is known to increase people's risk of cancer, but the study's findings showed that regular physical activity nearly canceled out this increased risk, according to the study, published today (Sept. 7) in the British Journal of Sports Medicine. [7 Cancers You Can Ward Off with Exercise]

Although it's not exactly clear how exercise may counteract the effects of alcohol when it comes to cancer risk, there are several mechanisms that could possibly explain the link, the researchers, led by Emmanuel Stamatakis, an associate professor of exercise, health and physical activity at the University of Sydney in Australia, wrote in the study.

Drinking alcohol, for example, has been shown to increase inflammation and decrease immune function, both of which have been linked to cancer, according to the study. Physical activity, on the other hand, has been shown to have the opposite effects — it decreases inflammation and increases immune function, the researchers wrote.

Ultimately, the mechanisms by which alcohol may cause cancer may be matched up with the mechanisms by which exercise may prevent it, but the two activities have opposite effects, the researchers wrote. In other words, the effects of exercise may cancel out those of alcohol. 

The danger of sedentary drinking

In the study, the researchers looked at the exercise and drinking habits of more than 36,000 men and women in England and Scotland.

The participants were divided into six groups based on their level of alcohol intake: those who never drank; former drinkers; occasional drinkers (meaning they hadn't had a drink in the past seven days); those who drank within the guidelines (no more than eight drinks/week for women or 12 drinks/week for men); "hazardous" drinkers (eight to 20 drinks/week for women, or 12 to 28 drinks/week for men); and "harmful" drinkers (more than 20 drinks/week for women and more than 28 drinks/week for men). [Here's How Much Alcohol Is OK to Drink in 19 Countries]

The people in the study were also divided into groups based on the amount of physical activity they reported. There was an "inactive" group, which got less than the study's recommended 150 minutes of exercise each week; a group that got the recommended amount of physical activity, and those who got double or more the recommended amount of physical activity.

The researchers found that for people in the inactive group, the more they drank, the more likely they were to die from any cause during the study period of about 10 years.

However, when exercise was added to the mix, the researchers found that people's risk of dying decreased, though it was still linked to the amount a person drank. And when the researchers looked at a person's risk of dying from cancer specifically, however, they found that getting the recommended amount of weekly exercise nearly canceled out this risk entirely. 

The exception in both cases was for those in the "harmful" drinking group. Among these heavier drinkers, exercise did not lower the risk of dying, the researchers found.

In addition, exercise did not have an effect on an alcohol drinker's risk of dying from heart disease, according to the study.

Finally, the researchers found that there was a slightly beneficial effect to having an occasional drink: regardless of physical activity level, occasional drinkers were slightly less likely die from any cause, or from heart disease in particular, compared with other groups of drinkers. An occasional drink didn't have any beneficial effect on reducing a person's risk of dying from cancer, however.  

The researchers noted that there were several limitations to the study. While they looked at the amount of alcohol the participants drank, they did not look at the pattern of drinking, so they may have missed binge drinking, they wrote. In addition, the researchers didn't consider other factors, such as diet, that may have an effect on a person's risk of dying.

Originally published on Live Science

Copyright 2016 LiveScience, a Purch company. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.