Type 2 diabetes mellitus (T2DM) is an endocrine-related disease with an increasing incidence worldwide. Male sexual dysfunction is common in diabetic patients. Therefore, we designed a Mendelian randomization (MR) study to investigate the association of type 2 diabetes and 3 glycemic traits with testosterone levels. Uncorrelated single nucleotide polymorphisms (SNPs) associated with T2DM (N = 228), fasting insulin (N = 38), fasting glucose (N = 71), and HbA1c (N = 75) at the genome-wide significance were selected as instrument variables. Genetic associations with testosterone levels (total testosterone, TT, bioavailable testosterone, BT, and sex hormone-binding globulin, SHBG) were obtained from the UK Biobank studies and other large consortia. Two-sample MR analysis was used to minimize the bias caused by confounding factors and response causality. Multivariable MR analysis was performed using Body mass index (BMI), Triglycerides (TG), LDL cholesterol (LDL), and adiponectin to adjust for the effects of potential confounders. Type 2 diabetes mellitus was associated with the decrease of total testosterone (β: -0.021,95%CI: -0.032, -0.010, p<0.001) and sex hormone binding globulin (β: -0.048,95%CI: -0.065, -0.031, p<0.001). In males, total testosterone (β: 0.058, 95% CI: 0.088, 0.028, p < 0.001) decreased. In females, it was associated with an increase in bioavailable testosterone (β: 0.077,95%CI: 0.058,0.096, p<0.001). Each unit (pmol/L) increase in fasting insulin was associated with 0.283nmol/L decrease in sex hormone-binding globulin (95%CI: -0.464, -0.102, p=0.002) and 0.260nmol/L increase in bioavailable testosterone (95%CI: -0.464, -0.102, p= 0.002). In males, sex hormone binding globulin decreased by 0.507nmol/L (95%CI: -0.960, -0.054, p= 0.028) and bioavailable testosterone increased by 0.216nmol/L (95%CI: 0.087,0.344, p= 0.001). In females, sex hormone binding globulin decreased by 0.714 nmol/L (95%CI: -1.093, -0.335, p<0.001) and bioavailable testosterone increased by 0.467nmol/L (95%CI: 0.286,0.648, p<0.001). Each unit (%) increase in HbA1c was associated with 0.060nmol/L decrease in sex hormone-binding globulin (95%CI: -0.113, -0.007, p= 0.026). In males, total testosterone decreased by 0.171nmol/L (95%CI: -0.288, -0.053, p=0.005) and sex hormone binding globulin decreased by 0.206nmol/L (95%CI: -0.340, -0.072, p=0.003). Total testosterone increased by 0.122nmol/L (95%CI: 0.012,0.233, p=0.029) and bioavailable testosterone increased by 0.163nmol/L (95%CI: 0.042,0.285, p=0.008) in females. Using MR Analysis, we found independent effects of type 2 diabetes, fasting insulin, and HbA1c on total testosterone and sex hormone-binding globulin after maximum exclusion of the effects of obesity, BMI, TG, LDL and Adiponectin.