Background Gestational diabetes mellitus (GDM), a severe pregnancy disorder, is a temporary form of diabetes that occurs during gestation. Astragaloside IV (AS IV), a natural and effective composition of Astragalus membranaceus , shows pharmacological effects against diabetes. On the contrary, the effects of AS IV on GDM development are still not clear. This study aims to investigate the role of AS IV in alleviating GDM in rats and determine whether AS IV exerts its anti-GDM properties through the regulation of gut microbiota and metabolite modulation. Methods There were six pregnant SD rats in each of the four groups. First, the GDM model was induced by the streptozotocin (STZ, 45 mg/kg) injection on gestational days (GDs) 1–4, and AS IV intervention (10 mg/kg/d) was administered from 6 days before pregnancy until delivery. The measurements of relevant indicators pertaining to GDM symptoms and reproductive outcomes, along with the 16S rRNA sequencing data and LC-MS-based metabolomic profiles, were assessed across all groups. Results After the 25-day intervention, the GDM model + AS IV group showed significantly decreased fasting blood glucose levels ( p = 0.0003), mean insulin levels ( p = 0.0001), and insulin resistance index ( p = 0.0001). AS IV treatment also decreased the malformation rate ( p = 0.0373) and increased the average fetal weight ( p = 0.0020) of GDM rats. Compared to the control rats, GDM rats showed a significantly higher abundance of Blautia and Anaerobiospirillum . However, the dramatically elevated abundance of these microorganisms was markedly decreased by AS IV treatment. In contrast, compared to GDM rats without treatment, GDM rats treated with AS IV showed a significantly higher abundance of bacteria ( p < 0.05), such as Methanobrevibacter , Dubosiella , and Romboutsia , which are beneficial to the rats. Additionally, we observed dramatically elevated production of metabolites, such as N-acetyl-l-leucine and lithocholic acid, after AS IV treatment through metabolomics analysis ( p < 0.05). Furthermore, significant associations between most genera of gut bacteria and the altered levels of the metabolites connected to gut microbiota were also discovered. Conclusion Our study demonstrated that AS IV could be an effective nutritional intervention strategy for targeting gut microbiota and metabolome profiles in GDM and provided experimental evidence supporting the use of AS IV to treat GDM.