The aim of this study were to understand the intake of selected metals (copper (Cu), zinc (Zn), iron (Fe) and magnesium (Mg)) during pregnancy; to detect serum Cu, Mg, Zn and Fe levels in pregnant women; to analyze the relationships among the selected metals, maternal thyroid function and fasting blood glucose (FBG) levels; to investigate the impact of the selected metals and maternal thyroid function on the risk of gestational diabetes mellitus (GDM); and to provide clinical value for the rational intake of the selected metals and iodine during pregnancy to ensure normal fetal development. The population was recruited from pregnant women presenting to the obstetrics outpatient clinic of Shanxi Provincial People's Hospital (February 2021 to April 2022). Selected metal, thyroid hormone (TH (free thyroxine (FT4), free tri-iodothyronine (FT3), and thyroid-stimulating hormone (TSH)) and FBG levels were measured in pregnant women during early, middle and late pregnancy. Covariance analysis was used to analyze the overall trends in selected metal, TH and FBG levels during pregnancy, and binary logistic regression models were used to assess the impacts of the selected metals and thyroid function on the risk of GDM. In addtion, the potential mediation effects of thyroid functions were explored in the mediation analyses. A total of 65 pregnant women were included in this study. Regression models showed that maternal Mg and Cu levels were positively associated with the risk of GDM, conversely, logFT4 was negatively associated with the risk of GDM. Mediation analyses suggested that the associations between the selected metals (Zn, Cu and Mg) and GDM might be mediated by FT3 levels, and that the Cu-GDM and Zn-GDM association could be explained by FT4 levels. Additionally, the Zn-GDM association could also potentially be mediated by the FT3/FT4 ratio. Our findings suggest that Mg, Cu and FT4 levels may act as influencing factors for the development of GDM, and maternal FT3, FT4 and the FT3/FT4 ratio might be the potential mediators of the associations between the selected metals and GDM risk during pregnancy.