Statins increase the risk of new-onset type 2 diabetes mellitus. We aimed to assess whether this increase in risk is a consequence of inhibition of 3-hydroxy-3-methylglutaryl-CoA reductase (HMGCR), the intended drug target. We used single nucleotide polymorphisms in the HMGCR gene, rs17238484 (for the main analysis) and rs12916 (for a subsidiary analysis) as proxies for HMGCR inhibition by statins. We examined associations of these variants with plasma lipid, glucose, and insulin concentrations; bodyweight; waist circumference; and prevalent and incident type 2 diabetes. Study-specific effect estimates per copy of each LDL-lowering allele were pooled by meta-analysis. These findings were compared with a meta-analysis of new-onset type 2 diabetes and bodyweight change data from randomised trials of statin drugs. The effects of statins in each randomised trial were assessed using meta-analysis. Data were available for up to 223 463 individuals from 43 genetic studies. Each additional rs17238484-G allele was associated with a mean 0·06 mmol/L (95% CI 0·05-0·07) lower LDL cholesterol and higher body weight (0·30 kg, 0·18-0·43), waist circumference (0·32 cm, 0·16-0·47), plasma insulin concentration (1·62%, 0·53-2·72), and plasma glucose concentration (0·23%, 0·02-0·44). The rs12916 SNP had similar effects on LDL cholesterol, bodyweight, and waist circumference. The rs17238484-G allele seemed to be associated with higher risk of type 2 diabetes (odds ratio [OR] per allele 1·02, 95% CI 1·00-1·05); the rs12916-T allele association was consistent (1·06, 1·03-1·09). In 129 170 individuals in randomised trials, statins lowered LDL cholesterol by 0·92 mmol/L (95% CI 0·18-1·67) at 1-year of follow-up, increased bodyweight by 0·24 kg (95% CI 0·10-0·38 in all trials; 0·33 kg, 95% CI 0·24-0·42 in placebo or standard care controlled trials and -0·15 kg, 95% CI -0·39 to 0·08 in intensive-dose vs moderate-dose trials) at a mean of 4·2 years (range 1·9-6·7) of follow-up, and increased the odds of new-onset type 2 diabetes (OR 1·12, 95% CI 1·06-1·18 in all trials; 1·11, 95% CI 1·03-1·20 in placebo or standard care controlled trials and 1·12, 95% CI 1·04-1·22 in intensive-dose vs moderate dose trials). The increased risk of type 2 diabetes noted with statins is at least partially explained by HMGCR inhibition. The funding sources are cited at the end of the paper.