It's not only the Mediterranean diet, but the whole "Mediterranean lifestyle" that can make a difference in your mental health, a new study from Spain found.

People in the study who ate a diet rich in fruit and veggies, and who also exercised and socialized a lot were less likely to develop depression than those who didn't follow this type of lifestyle, the findings showed.

Previous studies have shown a link between adhering to the Mediterranean diet or other healthy dietary patterns and a lower risk of depression, said lead study authorAlmudena Sánchez-Villegas, an associate professor of preventive medicine and public health at the University of Las Palmas de Gran Canaria, in Spain. But the new study is the first to examine the link between the overall Mediterranean lifestyle, beyond the diet itself, and depression, she told Live Science.

In the study, the researchers asked 11,800 people in Spain what they normally ate, how much they exercised and how much time they spent socializing with friends, to measure how closely these individuals adhered to the Mediterranean lifestyle. Scientists then tracked how many of the participants were diagnosed with depression during the next 8.5 years, on average. [7 Ways Depression Differs in Men and Women]

The researchers found that, by the end of the study period, 806 people in the study were diagnosed with depression.

To look at the relationship between how closely the people adhered to the Mediterranean lifestyle at the beginning of the study and how likely they were to later develop depression, the researchers divided the participants into three groups: those who adhered to the Mediterranean lifestyle the most, those who adhered to it to a moderate extent and those who adhered to it the least.

Those people in the group with the closest adherence to the Mediterranean lifestyle at the beginning of the study were 50 percent less likely to be diagnosed with depression during the study period than those in the group with the least adherence to this lifestyle. [9 DIY Ways to Improve Your Mental Health]

The researchers said they don't know for sure why eating a healthy diet, exercising and socializing may be linked to a lower risk of depression, but several mechanisms may be involved in this link. For example, certain components of the Mediterranean diet — such as olive oil, nuts, legumes, fruit and fish — have beneficial nutrients that have anti-inflammatory properties, Sánchez-Villegas said. These properties may be useful in preventing inflammation, which has previously been linked to a higher risk of depression, she said.

Exercise may also help protect people against inflammation and therefore reduce the risk of depression, Sánchez-Villegas said. Moreover, exercise has been known to stimulate the secretion of feel-good chemicals called endorphins that enhance mood, which may also help prevent depression, she said.

In addition, the new findings are in line with previous research that has linked greater social interaction with better psychological well-being, the researchers said in their study, published Aug. 9 in the journal Clinical Psychological Science. The authors of that previous research on depression and social factors have suggested that multiple mechanisms, including having social support during difficult times, may explain this link.

Originally published on Live Science.