Researchers found joining a religious organisation was the best way of combating the condition.
Experts at the London School of Economics and Political Science (LSE) could not say whether it was having a faith that caused the beneficial effect, or if it was simply because it gave people a sense of belonging.
Their analysis of 9,000 Europeans aged 50-plus involved looking at different levels of social activity and how they influenced people's moods.
LSE epidemiologist Dr Mauricio Avendano said the only activity associated with sustained happiness was attending a church, synagogue or mosque.
"The church appears to play a very important social role in keeping depression at bay and also as a coping mechanism during periods of illness in later life," he said.
"It is not clear to us how much this is about religion per se, or whether it may be about the sense of belonging and not being socially isolated.
"One of the most puzzling findings is that although healthier people are more likely to volunteer, we found no evidence that volunteering actually leads to better mental health. It may be that any benefits are outweighed by other negative impacts of volunteering, such as stress."
The study did not find any short-term benefits from sports and participation in other social activities.
They said that according to the recent Global Burden of Disease study, the incidence of depression among older Europeans ranges from 18% in Denmark to 37% in Spain.
The study, which was carried out in collaboration with Erasmus University Medical Centre (Erasmus MC) in Rotterdam, Netherlands, is published in the American Journal of Epidemiology.
If you feel depressed you can get help from Premier Lifeline, the national Christian helpline, on 0300 111 0101.
Premier's Marcus Jones speaking to Dr Mauricio Avendano and then Premier's Johnathan Clarke on the News Hour: