Statins have previously been associated with higher rates of type 2 diabetes, but it was not clear whether the drugs were responsible or some other coincidental factor.
Now a study has produced strong evidence that the drugs' basic mechanism can lead to weight gain and a modest increase in diabetes risk.
However, experts said the benefits of taking statins still greatly outweigh the risks and advice on taking the drugs should not be changed.
Scientists analysed genetic data from up to 220,000 people and results from almost 130,000 patients who took part in earlier statin trials.
They found patients taking statins experienced a modest 12% increased risk of developing type 2 diabetes over a four-year period, and gained around half a pound (240 grams) in weight on average.
Statins work by reducing the efficiency of a liver enzyme, causing liver cells to trap more low-density lipoprotein (LDL) - the harmful form of cholesterol - from the bloodstream.
The cholesterol is converted to bile salts and eliminated naturally from the body.
Lead researcher Dr Daniel Swerdlow, from University College London's Institute of Cardiovascular Science, said: "Commonly occurring variants in the gene encoding the same liver enzyme are associated with a lower LDL cholesterol.
"Incorporating information from up to 220 000 individuals, we found that these genetic variants were also associated with a higher weight and marginally higher type 2 diabetes risk.
"The effects were very much smaller than from statin treatment, but the genetic findings indicate that the weight gain and diabetes risk observed in the analysis from trials are related to the known mechanism of action of statins rather than some other unintended effect."
Story continues below...
The findings are published in the latest online edition of The Lancet medical journal.
Co-author Professor Aroon Hingorani, director of the UCL institute, stressed that the effects of the genetic variants were "orders of magnitude" lower than those of statins.
"The genetic findings of our study help to explain the mechanism by which statins increase weight and diabetes risk," he said.
He added there was "no indication" that individuals' genetic make-up meaningfully influenced the response to statin treatment.
Current clinical guidelines suggest that statins should be offered to people with a 10% or higher risk of developing heart disease in the next 10 years.
Statins are also recommended for patients who have had a heart attack or stroke to reduce the risk of future incidents.
Professor Naveed Sattar, another member of the research team from the University of Glasgow's Institute of Cardiovascular and Medical Sciences, said: "Previous analyses have indicated that the cardiovascular benefits of statin treatment greatly outweigh the risk of new-onset type 2 diabetes.
"Nevertheless, many patients eligible for statin treatment would also benefit from lifestyle changes including increased physical activity, eating more healthily and stopping smoking.
"The modest increases in weight and diabetes risk seen in this study could easily be mitigated by adopting healthier diets and lifestyles. Reinforcing the importance of lifestyle changes when discussing these issues with patients would further enhance the benefit of statin treatment in preventing heart attacks and strokes."
Professor Jeremy Pearson, associate medical director of the British Heart Foundation, which co-funded the study, said: "This study should reassure people that the benefits of taking statins far outweigh the small effect on diabetes risk. But the results also reinforce that, alongside prescribed medication, taking steps to maintain a healthy weight is essential to stay heart healthy."
Professor Colin Baigent, deputy director of Oxford University's Clinical Trial Service and Epidemiological Studies units, said: "Although it is helpful to understand mechanisms, this research does not change our assessment of the safety of statins. The magnitude of the benefits of statins arising from the prevention of heart attacks and strokes greatly outweighs any small risks of diabetes, so the current recommendations for statin use remain appropriate."Suggest a correction