The secret to a longer life is to marry someone the same age, at least if you are a woman, researchers say.

Marriage generally improves life expectancy, but the age gap between a couple affects the life expectancy of men and women very differently.

Marrying an older man shortens a woman's lifespan, but having a younger husband reduces it even more, the study found.

The findings, drawn from the medical records of two million Danish couples, suggest that the best a woman can do is marry a man of about the same age.

Health records have shown previously that men live longer if they have a younger wife, an effect researchers expected to see mirrored in women who married younger men.

But a study by Sven Drefahl at the Max Planck Institute for Demographic Research in Rosktock, Germany, shows that the greater the age gap between a woman and her husband, the shorter her life expectancy, regardless of whether he is older or younger.

According to Drefahl's report in the journal Demography, a man who is between seven and nine years older than his wife has an 11% lower mortality rate than a man whose wife is the same age as him. However, a woman who is between seven and nine years older than her husband has a 20% greater mortality rate than if she were with a man the same age.

Researchers used to think that healthier individuals were in a better position to choose younger spouses and so already had a longer life expectancy. A younger spouse may also have a beneficial psychological effect on the older partner and provide them with better care in old age.

However, Drefahl's study casts doubt on these ideas, since they do not hold for women marrying younger men.

"These theories now have to be reconsidered," said Drefahl. "The reasons for mortality differences due to the age gap of the spouses remain unclear."

Some explanation may lie in the quality of friendships men and women form throughout life. Women tend to have more close friendships outside marriage and so benefit less than men from having a partner. "Unlike the benefits of a younger wife, a younger husband wouldn't help extend the life of his older wife by taking care of her, going for a walk with her and enjoying late life together. She already has friends for that. The older man, however, doesn't," said Drefahl.

Women with much younger husbands may die younger on average because they experience more stress, Drefahl speculates.

Women marrying a partner seven to nine years younger increase their relative mortality risk by 20% compared with couples where both are the same age. But the relative mortality risk of a husband who is seven to nine years older is reduced by 11%. Source: Sven Drefahl US Census Bureau

While the study shows that women on average die younger if there is a large age gap in their relationship, married men and women both tend to live longer than unmarried individuals.

The life expectancy of women in general is higher than men, with women born in the UK expected to live to 82 years on average, compared with 78 years for men.