AimsDeep metagenomics offers an advanced tool for examining the relationship between gut microbiota composition and function and the onset of disease; in this case, does the composition and function of gut microbiota during pregnancy differ in women who develop prediabetes and those who do not at two-year postpartum, and whether the gut microbiota composition associates with glycemic traits.MethodsIn total, 439 women were recruited in early pregnancy. Gut microbiota was assessed by metagenomics analysis in early (13.9 ± 2.0 gestational weeks) and late pregnancy (35.1 ± 1.0 gestational weeks). Prediabetes was determined using American Diabetes Association criteria as fasting plasma glucose 5.6–6.9 mmol/l analyzed by an enzymatic hexokinase method. Of the women, 39 (22.1%) developed prediabetes by two-year postpartum.ResultsThe relative abundances ofEscherichia unclassified(FDR < 0.05),Clostridiales bacterium1_7_ 47FAA (FDR < 0.25) andParabacteroides(FDR < 0.25) were higher, and those ofRuminococcaceae bacteriumD16 (FDR < 0.25), Anaerotruncus unclassified(FDR < 0.25) andRuminococcaceae noname(FDR < 0.25) were lower in early pregnancy in those women who later developed prediabetes. In late pregnancy,Porphyromonaswas higher andRuminococcussp 5_1_39BFAA was lower in prediabetes (FDR < 0.25). Furthermore, fasting glucose concentrations associated inversely withAnaerotruncus unclassifiedin early pregnancy and directly withRuminococcussp 5_1_39BFAA in late pregnancy (FDR < 0.25). α-Diversity orβ-diversity did not differ significantly between the groups. Predictions of community function during pregnancy were not associated with prediabetes.ConclusionsOur study shows that some bacterial species during pregnancy contributed to the onset of prediabetes within two-year postpartum. These were attributable primarily to a lower abundance of short-chain fatty acids-producing bacteria.Supplementary InformationThe online version contains supplementary material available at 10.1007/s00592-023-02064-5.