Sex can save your life.

Getting it on increases long-term survival rates after a heart attack, according to a new study published in the American Journal of Medicine.

The 1,120 male and female participants, all 65 or younger at the time of their first heart attack in 1992 or 1993, were tracked by researchers through 2015.

By then, 524 of them had died.

Of the survivors, those who had done the deed multiple times a week were 27% less likely to die during the study period. Those who got lucky once a week were 12% less likely to die, and those who scored some tail infrequently were 8% less likely to die.

Post-heart attack intercourse was even more vital for a longer life, researchers found.

Doing it weekly following a heart attack decreased mortality rates by 37%, more than once a week meant a 33% survival bump, and less than once a week made for a 28% increased life expectancy, compared to participants who never got any at all after their heart attack.

Age, health and relationship status were also predictive death rate factors.

“Not surprisingly, the people who were sexually active were more likely to be in a relationship, were younger and generally healthier,” Andrew Steptoe, head of University College London’s Research Department of Behavioural Science and Health, tells Reuters.

Participants who got the most prior to their heart attacks were on average 49 years old, researchers found, while those not getting any were around 58 — and more likely to have high blood pressure, high cholesterol, diabetes and chronic health problems.

“Sexual activity is often part of a close and loving relationship as people age, but the relationship is probably more important than the sex,” says Steptoe, who was not involved in the new study. “Although regular sex is part of healthy aging, people should not feel that they ‘ought’ to have sex in order to try to live longer.”

Less than half of the celibates lived with a partner — while 94% of those having sex multiple times a week had live-in lovers — and a majority 67% hadn’t exercised at all in the year before their heart attack, while 45% of the most voracious love-makers did.

Adjusting for age, lifestyle, socioeconomic factors and health concerns weakened the connection between sex and survival, study authors found, noting that sexual activity is possibly a sign and not a cause of superior health.

Heart attacks during sex, however, can be lethal. Research in 2017 found that less than one in five men survive when their heart attack occurs midcoitus.