Testing semen in this way could one day be used to predict and prevent future health problems, researchers suggest.
For the study, published in the journal Human Reproduction, academics analysed data from 78,284 men in Denmark between 1965 and 2015.
The men had their semen quality assessed during the period due to reported couple infertility.
It was found that those with a higher total motile count (TMC) - or sperm that can move or swim - could expect to live longer.
"Previous research has suggested that male infertility and lower semen quality could be associated with mortality," said Dr Larke Priskorn, a senior researcher in the department of growth and reproduction at Copenhagen University Hospital.
"We conducted this study to test the hypothesis and at the same time get an absolute estimate of how much semen quality predicts a man's lifespan and to understand whether diagnosed diseases prior to semen quality assessment might explain some of the reported association.
"We calculated the men's life expectancy according to their semen quality and found that men with the best quality could expect to live two to three years longer, on average, than men with the lowest semen quality."
Men with a TMC of more than 120 million - which is considered healthy - lived 2.7 years longer than men with a TMC of between zero and five million.
"The lower the semen quality, the lower the life expectancy," Priskorn said.
"This association was not explained by any diseases in the 10 years before semen quality assessment or the men's educational level."
Researchers suggest assessing fertility, which is usually done when men are relatively young, could be an opportunity for detecting the risk of other health problems.
"We need to better understand the association between semen quality and men's general health," said Dr Niels Jorgensen, chief andrologist at the department of growth and reproduction at Copenhagen University Hospital.
"However, this study suggests that we can identify subgroups of men with impaired semen quality who are apparently healthy when their semen quality is assessed, but who are at increased risk of developing certain diseases later in life.
"Thus, fertility evaluations, which are typically conducted when the men are relatively young, would serve as an opportunity for detecting and mitigating the risks of other health problems in the longer term."
During the follow-up period, 8600 men died, the equivalent of 11 per cent of the total group.
Some 59,657 men provided semen samples between 1987 and 2015, with more information on their education level and diagnoses of medical conditions in the 10 years prior available.