The gut microbiota (GM) is essential for mammalian health. Although the association between infant GM and breast milk (BM) composition has been well established in humans, such a relationship has not been investigated in horses. Hence, this study was conducted to analyze the GM formation of foals during lactation and determine the presence of low-molecular-weight metabolites in mares’ BM and their role in shaping foals’ GM. The fecal and BM samples from six pairs of foals and mares were subjected to 16S ribosomal RNA metagenomic and metabolomic analyses, respectively. The composition of foal GM changed during lactation time; hierarchical cluster analysis divided the fetal GM into three groups corresponding to different time points in foal development. The level of most metabolites in milk decreased over time with increasing milk yield, while threonic acid and ascorbic acid increased. Further analyses revealed gut bacteria that correlated with changes in milk metabolites; for instance, there was a positive correlation between Bacteroidaceae in the foal’s gut microbiota and serine/glycine in the mother’s milk. These findings help improve the rearing environment of lactating horses and establish artificial feeding methods for foals.