The onset of diabetes more than doubles a patient's risk of suffering depression or other mood disorders.
But researchers in Australia and Taiwan also found that metformin, the most commonly used medication for type-2 diabetes, more than halves this risk.
Monash University researcher Mark Wahlqvist, who sifted through 12 years of medical records of adults in Taiwan, said metformin reduced the incidence of dementia and Parkinson's disease as well as mood disorders, especially when used with a sulfonylurea drug to increase the production of insulin.
"Fortunately, we had sufficient patients not on metformin to make the comparison," he said.
"We think the key mechanism relates to mitochondrial function and cellular bioenergetics - metformin would seem to reset impaired energy regulation, perhaps through its action on the enzyme AMP kinase."
Prof Wahlqvist, who led a joint study by his university in Melbourne and the National Health Research Institutes Taiwan, said his study was into type-2 diabetes, but the findings were likely to be valid for type-1 diabetes as well.
The survey was published in the journal BMC Medicine.