Background and objectives Sex steroid hormones have been hypothesized to be associated with the risk of gastric cancer (GC); however, it has not been widely validated in prospective studies. We aimed to investigate the associations between sex steroid hormone metabolites and the risk of gastric cancer and precancerous lesions in a prospective cohort of Chinese men. Methods Using liquid chromatography-tandem mass spectrometry (LC-MS/MS) and electrochemical luminescence immunoassay, we examined 20 sex steroid hormone metabolites and sex hormone-binding globulin (SHBG) in serum from 470 eligible men, including high-grade lesions or GC ( n = 32), intestinal metaplasia (IM, n = 146), and 1:2 matched normal participants ( n = 292) from 2007 to 2012. IM and normal participants were further followed up until December 2021, during which 32 new GC cases were identified with a median follow-up of 11.8 years. Associations between baseline sex steroid hormone metabolites and IM, high-grade lesions and gastric cancer were assessed using logistic regression, and associations between sex steroid hormone metabolites and incident GC risk were assessed using Cox proportional hazards regression in the prospective analysis. Results In the cross-sectional analysis, androstenedione levels were potentially associated with IM risk and significantly associated with high-grade lesions or GC risk (OR continuous = 2.45, 95% CI: 1.01–5.95). Higher concentrations of 17α-hydroxypregnenolone (OR continuous = 2.35, 95% CI: 1.13–4.88), progesterone (OR continuous = 2.68, 95% CI: 1.09–6.61), and estrone (OR continuous = 5.36, 95% CI: 1.28–22.52) were also associated with an increased risk of high-grade lesions or GC. Furthermore, significant positive associations between GC risk and serum levels of SHBG (HR continuous = 2.57, 95% CI: 1.04–6.36), epitestosterone (HR continuous = 2.10, 95% CI: 1.07–4.15) and pregnenolone (HR continuous = 1.30, 95% CI: 1.03–1.63) were identified in the follow-up study focusing on participants diagnosed as normal or IM. Notably, the subgroup analyses stratified by H. pylori status revealed similar associations between androstenedione, 17α-hydroxypregnenolone, progesterone, estrone, SHBG, pregnenolone, and GC risk. Conclusions Several sex hormone metabolites were significantly associated with gastric cancer and its precancerous lesions, indicating a role for sex hormones in gastric carcinogenesis and potentially providing novel biomarkers for the identification of high-risk populations and risk prediction for GC.