Administration of all-trans retinoic acid (ATRA) to pregnant sows improves developmental defects of Hoxa1–/– fetal pigs, and this study aimed to explore the influence of maternal ATRA administration during pregnancy on gut microbiota of neonatal piglets. Samples of jejunal and ileal meconium of neonatal piglets before suckling were collected including 5 Hoxa1–/– and 20 non-Hoxa1–/– (Hoxa1+/+ and Hoxa1+/−) neonatal piglets from the control group and 5 Hoxa1–/– and 7 non-Hoxa1–/– neonatal piglets from the experimental group. Results indicated that Hoxa1 mutation shaped the bacterial composition of the jejunum and ileum of neonatal piglets and Hoxa1–/– neonatal piglets had significantly higher diversity and species richness, higher relative abundance of phylum Bacteroidetes, lower relative abundances of phylum Firmicutes and genus Lactobacillus, and lower ratio of Firmicutes to Bacteroidetes than non-Hoxa1–/– neonatal piglets. After maternal ATRA administration, Hoxa1–/– neonatal piglets had significantly higher diversity and species richness, higher relative abundances of two bacterial phyla (Bacteroidetes and Proteobacteria), and lower relative abundances of phylum Firmicutes and genus Lactobacillus in the jejunum than non-Hoxa1–/– neonatal piglets. Hoxa1–/– neonatal piglets delivered by sows with maternal ATRA administration had lower diversity and species richness and higher relative abundance of phylum Firmicutes in the jejunum than Hoxa1–/– neonatal piglets born by sows with no maternal ATRA administration. Non-Hoxa1–/– neonatal piglets delivered by sows with maternal ATRA administration had higher diversity and species richness and significantly lower relative abundances of phyla Firmicutes and Actinobacteria and genus Lactobacillus in the ileum than non-Hoxa1–/– neonatal piglets born by sows with no maternal ATRA administration. Hoxa1 mutation decreased the expression of bacterial genes involved in ABC transporters, purine metabolism, and aminoacyl-tRNA biosynthesis and increased the expression of bacterial genes involved in two-component system, starch and sucrose metabolism, and arginine and proline metabolism. Maternal ATRA administration decreased the expression of bacterial genes involved in arginine and proline metabolism, peptidoglycan biosynthesis, and fatty acid biosynthesis. Hoxa1 mutation resulted in bacterial dysbiosis of the small intestine of Hoaxa1–/– neonatal piglets, and maternal ATRA administration restored the bacterial dysbiosis of Hoxa1–/– neonatal piglets and altered the bacterial composition of the small intestine of non-Hoxa1–/– neonatal piglets.