Drinking coffee may do more than just keep you awake. A new study suggests an intriguing potential link to mental health later in life, as well.

A team of Swedish and Danish researchers tracked coffee consumption in a group of 1,409 middle-age men and women for an average of 21 years. During that time, 61 participants developed dementia, 48 with Alzheimer’s disease.

After controlling for numerous socioeconomic and health factors, including high cholesterol and high blood pressure, the scientists found that the subjects who had reported drinking three to five cups of coffee daily were 65 percent less likely to have developed dementia, compared with those who drank two cups or less. People who drank more than five cups a day also were at reduced risk of dementia, the researchers said, but there were not enough people in this group to draw statistically significant conclusions.

Dr. Miia Kivipelto, an associate professor of neurology at the Karolinska Institute in Stockholm and lead author of the study, does not as yet advocate drinking coffee as a preventive health measure. “This is an observational study,” she said. “We have no evidence that for people who are not drinking coffee, taking up drinking will have a protective effect.”