Gut microbiota affects the gut–brain axis; hence, the modulation of the microbiota has been proposed as a potential therapeutic strategy for cerebral ischemia/reperfusion injury (CIRI). However, the role and mechanism of the gut microbiota in regulating microglial polarization during CIRI remain poorly understood. Herein, using a middle cerebral artery occlusion and reperfusion (MCAO/R) rat model, we evaluated changes in the gut microbiota after CIRI and the potential effects of fecal microbiota transplant (FMT) on the brain. Rats underwent either MCAO/R or sham surgery, and then they received FMT (started 3 days later; continued for 10 days). 2,3,5-Triphenyltetrazolium chloride staining, neurological outcome scale, and Fluoro-Jade C staining showed that MCAO/R induced cerebral infarction, neurological deficits, and neuronal degeneration. In addition, immunohistochemistry or real-time PCR assay showed increased expression levels of M1-macrophage markers—TNF-α, IL-1β, IL-6, and iNOS—in the rats following MCAO/R. Our finding suggests that microglial M1 polarization is involved in CIRI. 16 S ribosomal RNA gene sequencing data revealed an imbalance in the gut microbiota of MCAO/R animals. In contrast, FMT reversed this MCAO/R-induced imbalance in the gut microbiota and ameliorated nerve injury. In addition, FMT prevented the upregulation in the ERK and NF-κB pathways, which reversed the M2-to-M1 microglial shift 10 days after MCAO/R injury in rats. Our primary data showed that the modulation of the gut microbiota can attenuate CIRI in rats by inhibiting microglial M1 polarization through the ERK and NF-κB pathways. However, an understanding of the underlying mechanism requires further study.