Regular physical activity lasting 45 minutes three to five times a week can reduce poor mental health - but doing more than that is not always beneficial, a large US study suggests.
A total of 1.2 million people reported their activity levels for a month and rated their mental wellbeing.
People who exercised had 1.5 fewer "bad days" a month than non-exercisers, the study found.
Team sports, cycling and aerobics had the greatest positive impact.
All types of activity were found to improve mental health no matter people's age or gender, including doing the housework and looking after children.
The study, published in The Lancet Psychiatry Journal, is the largest of its kind to date but it cannot confirm that physical activity is the cause of improved mental health.
Previous research into the effects of exercise on mental health have thrown up mixed results, and some studies suggest that lack of activity could lead to poor mental health as well as being a symptom of it.
Exercise is already known to reduce the risk of heart disease, stroke and diabetes.
Adults taking part in the study said they experienced on average 3.4 days of poor mental health each month. For those who were physically active, this reduced to only two days.
Among people who had been diagnosed previously with depression, exercise appeared to have a larger effect, resulting in seven days of poor mental health a month compared with nearly 11 days for those who did no exercise.
How often and for how long people were active was also important.
Being active for 30 to 60 minutes every second day came out as the optimal routine.
But there could be such a thing as doing too much exercise, the study concluded.
Adam Chekroud, study author and assistant professor of psychiatry at Yale University, said: "Previously, people have believed that the more exercise you do, the better your mental health, but our study suggests that this is not the case.
"Doing exercise more than 23 times a month, or exercising for longer than 90-minute sessions is associated with worse mental health."
He said the positive impact of team sports suggested that social sports activities could reduce isolation and be good for resilience, while also reducing depression.
The findings back up UK government guidelines recommending that people should do 150 minutes of physical activity per week.
But the study has some limitations. It is based on self-reporting, which is not always accurate, and there is no way of measuring physical activity.
Dean Burnett, neuroscientist and honorary research associate, from the school of psychology at Cardiff University, said the link between exercise and mental health had been difficult to pin down but this large study "strongly suggests that there is a definite association between the two".
"However, the nature of the study means it's difficult to say more than that with any real certainty," he said.
Stephen Lawrie, head of psychiatry at the University of Edinburgh, said it indicated that social and "mindful" exercise is particularly good for mental health - but not if it is overdone.
"I suspect we all know people who seem 'addicted' to exercise and if this starts to impact on other aspects of life - like foregoing social activities because one has to be up at the crack of dawn to run several miles - it might actually be bad for people," he added.