Our previous research reported that supplementation of Bacillus subtilis DSM 25841 promoted growth and disease resistance of weaned pigs under enterotoxigenic Escherichia coli (ETEC) challenge and its efficacy is comparable to carbadox. This follow-up study aimed to characterize the effects of ETEC infection, supplementing B. subtilis DSM 25841 or carbadox on intestinal microbiota of pigs. Forty-eight weaned pigs (6.17 ± 0.36 kg BW) were randomly allotted to one of four treatments: negative control (NC), positive control (PC), antibiotics (AGP, 50 mg/kg of carbadox), and direct fed microbials (DFM, 2.56 × 109 CFU/kg of B. subtilis). The experiment lasted 28 days with 7 days before and 21 days after first E. coli inoculation (day 0). Pigs in the PC, AGP, and DFM groups were orally inoculated with F18 ETEC for 3 consecutive days with 1010 CFU per dose per day. Fecal samples were collected on day -7, and day 7 and day 21 post inoculation, digesta samples were collected from jejunum, ileum, and distal colon on day 21 post inoculation to perform 16S rRNA sequencing. Sampling days and locations influenced (p < 0.05) Chao1 index and beta-diversity. Age increased (p < 0.05) the relative abundance of Firmicutes but decreased (p < 0.05) the relative abundance of Bacteroidetes in feces. ETEC infection increased (p < 0.05) the relative abundance of Proteobacteria in feces on day 7 post inoculation. AGP reduced (p < 0.05) relative abundance of Firmicutes and Lactobacillaceae in feces compared with PC and DFM. AGP reduced (p < 0.05) relative abundance of Bifidobacteriaceae in jejunum and ileum, while DFM reduced (p < 0.05) relative abundance of Actinomycetaceae in jejunum and Lachnospiraceae in ileum, compared with PC. Pigs fed with DFM had greater (p < 0.05) relative abundance of Ruminococcaceae, Veillonellaceae, Bifidobacteriaceae in jejunum, Lactobacillaceae in ileum and colon, and Bifidobacteriaceae in colon than pigs in AGP. Current results indicate that carbadox or B. subtilis had stronger influences on microbial diversity and composition in ileum than other intestinal segments and feces. Supplementation of B. subtilis could increase or maintain the relative abundance of beneficial bacteria in ileum compared with carbadox.