Background Increasing number of studies reported the positive effect of metformin on the prevention and treatment of cancers. However, the genetic causal effect of metformin utilization on the risk of common cancers was not completely demonstrated.Methods Two-sample Mendelian Randomization (two-sample MR) analysis was conducted to uncover the genetically predicted causal association between metformin use and 26 kinds of cancers. Besides, two-step Mendelian Randomization (two-step MR) assessment was applied to clarify the mediators which mediated the causal effect of metformin on certain cancer. We utilized five robust analytical methods, in which the inverse variance weighting (IVW) method served as the major one. Sensitivity, pleiotropy, and heterogeneity were assessed. The genetic statistics of exposure, outcomes, and mediators were downloaded from publicly available datasets, including the Open Genome-Wide Association Study (GWAS), FinnGen consortium (FinnGen), and UK Biobank (UKB).Results Among 26 kinds of common cancers, HER-positive breast cancer was presented with a significant causal relationship with metformin use (Beta: -4.0982; OR: 0.0166 (95%CI: 0.0008, 0.3376); P-value: 0.0077), which indicated metformin could prevent people from HER-positive breast cancer. Other cancers only showed modest associations with metformin use. Potential mediators were included in two-step MR, among which total testosterone levels (mediating effect: 24.52%) displayed significant mediating roles. Leave-one-out, MR-Egger, and MR-PRESSO analyses produced consistent outcomes.Conclusion Metformin use exhibited a genetically protective effect on HER-positive breast cancer, which was partially mediated by total testosterone levels.