Objective: To evaluate the relationship between serum mineral levels in pregnant women during the second and third trimesters and the risk of developing gestational diabetes mellitus (GDM). Design: Retrospective cohort study. Setting: A tertiary hospital in China. Population: Unselected women with singleton pregnancies who developed GDM. Methods: Maternal demographic data and serum mineral concentration information from the mid and late stages of pregnancy were collected through the hospital information system. Analyses were conducted using restricted cubic spline models and multivariate logistic regression models. Main outcome measures: The prevalence of GDM,specific serum mineral levels,gestational age at delivery. Results: Among 17 224 singleton pregnancies, the prevalence of GDM in this study was 15.07%. Chloride (P for overall = 0.01; P for nonlinear = 0.373; OR (95% CI) = 1.03 (1.01, 1.05)) showed a significant linear positive association with GDM. Additionally, serum levels of calcium (P for nonlinear < 0.001), potassium (P for nonlinear = 0.036), and magnesium (P for nonlinear < 0.001) were found to have nonlinear relationships with the risk of GDM. The interactions between calcium and magnesium (OR (95% CI) = 0.05 (0.01, 0.27), P for interaction < 0.001), potassium and magnesium (OR (95% CI) = 0.11 (0.03, 0.37), P for interaction < 0.001), and potassium and chloride (OR (95% CI) = 1.06 (1.01, 1.11), P for interaction < 0.001) were significant. Conclusions: The study indicates that specific serum mineral levels in pregnant women are closely associated with the risk of gestational diabetes mellitus. A deeper understanding of the mechanisms and interactions of these minerals could aid in developing effective prevention and treatment strategies, thereby reducing the incidence of GDM and improving pregnancy outcomes.