Microbial exposures and sex hormones exert potent effects on autoimmune diseases, many of which are more prevalent in women. We demonstrate that early-life microbial exposures determine sex hormone levels and modify progression to autoimmunity in the nonobese diabetic (NOD) mouse model of type 1 diabetes (T1D). Colonization by commensal microbes elevated serum testosterone and protected NOD males from T1D. Transfer of gut microbiota from adult males to immature females altered the recipient's microbiota, resulting in elevated testosterone and metabolomic changes, reduced islet inflammation and autoantibody production, and robust T1D protection. These effects were dependent on androgen receptor activity. Thus, the commensal microbial community alters sex hormone levels and regulates autoimmune disease fate in individuals with high genetic risk.