Background: Strong associations between obesity and type 2 diabetes with nonalcoholic fatty liver disease (NAFLD) have been discovered, but their causal relationships and interplay with genetic backgrounds have not been enough determined. We aimed to assess the causal association of type 2 diabetes and body mass index (BMI) with NAFLD using Mendelian randomization (MR) analysis and then whether type 2 diabetes and BMI genetic risk scores (GRSs) moderated these associations. Methods: A total of 8,944 participants were enrolled from 16 sites in East China from 2014-2016 from the SPECT-China study. We calculated the weighted diabetes and BMI GRSs based on 18 and 14 variants, respectively. Liver steatosis was determined by ultrasound. Results: Using MR analysis, the causal odds ratio (ORMR) of genetically determined BMI for NAFLD in all subjects was 1.434 (95% CI 1.234, 1.665), and for genetically determined diabetes, the association was insignificant (OR 1.098, 95% CI 0.890, 1.354). A significant interaction was found between DM_GRS and BMI_GRS (P for interaction = 0.018). Using stratification analyses, the ORMR of diabetes for NAFLD was 1.581 (95% CI 1.071, 2.233), which was in the lowest BMI_GRS quartile. However, the association was insignificant for the three higher BMI_GRS quartiles. Conversely, for subjects in DM_GRS quartiles one to three, the ORMRs of BMI for NAFLD were 1.769 (95% CI 1.203, 2.601), 1.325 (95% CI 1.025, 1,711) and 1.822 (95% CI 1.025, 2.933), although the association was insignificant in the highest DM_GRS. Conclusions: The causal associations of type 2 diabetes and BMI with NAFLD were significantly modulated by the diabetes and adiposity genetic risk showing a model of competing risks. Funding: This study was supported by National Natural Science Foundation of China (91857117, 81570726, 81600609); Science and Technology Commission of Shanghai Municipality (19140902400, 18410722300, 16411971200, 16410723200); the Major Science and Technology Innovation Program of Shanghai Municipal Education Commission (2018YFC1705103); Commission of Health and Family Planning of Pudong District (PWZxq2017-17, PW2015D-5); the Shanghai Municipal Commission of Health and Family Planning (20164Y0079); Municipal Human Resources Development Program for Outstanding Young Talents in Medical and Health Sciences in Shanghai (2017YQ053); Clinical Research Plan of SHDC (16CR3076B); Shanghai JiaoTong University School of Medicine (19XJ11007). Declaration of Interest: The authors declare no conflicts of interest. Ethical Approval: The study protocol was approved by the Ethics Committee of Shanghai Ninth People’s Hospital, Shanghai Jiao Tong University School of Medicine. The study protocol followed the ethical guidelines of the 1975 Declaration of Helsinki as reflected in a priori approval by the appropriate institutional review committee. Informed consent was obtained from all participants included in the study.