Abstract Background Previous studies have linked gut microbiota with cancer etiology, but the associations for specific gut microbiota are causal or owing to bias remain to be elucidated. Methods We performed a two‐sample Mendelian randomization (MR) analysis to assess the causal effect of gut microbiota on cancer risk. Five common cancers, including breast, endometrial, lung, ovarian, and prostate cancer as well as their subtypes (sample sizes ranging from 27,209 to 228,951) were included as the outcomes. Genetic information for gut microbiota was obtained from a genome‐wide association study (GWAS) comprising 18,340 participants. In univariable MR (UVMR) analysis, the inverse variance weighted (IVW) method was conducted as the primary method, with the robust adjusted profile scores, weighted median, and MR Egger used as supplementary methods for causal inference. Sensitivity analyses including the Cochran Q test, Egger intercept test, and leave‐one‐out analysis were performed to verify the robustness of the MR results. Multivariable MR (MVMR) was performed to evaluate the direct causal effects of gut microbiota on the risk of cancers. Results UVMR detected a higher abundance of genus Sellimonas predicted a higher risk of estrogen receptor‐positive breast cancer (OR = 1.09, 95% CI 1.05–1.14, p = 2.01 × 10−5), and a higher abundance of class Alphaproteobacteria was associated with a lower risk of prostate cancer (OR = 0.84, 95% CI 0.75–0.93, p = 1.11 × 10−3). Sensitivity analysis found little evidence of bias in the current study. MVMR further confirmed that genus Sellimonas exerted a direct effect on breast cancer, while the effect of class Alphaproteobacteria on prostate cancer was driven by the common risk factors of prostate cancer. Conclusion Our study implies the involvement of gut microbiota in cancer development, which provides a novel potential target for cancer screening and prevention, and might have an implication for future functional analysis.