Early-life antibiotic interventions can change the predisposition to disease by disturbing the gut microbiota. However, the impact of antibiotics on gut microbiota in the gastrointestinal tract is not completely understood, although antibiotic-induced alterations in the distal gut have been reported. Here, employing a piglet model, the microbial composition was analyzed by high-throughput 16S rRNA gene sequencing and PICRUSt predictions of metagenome function. The present study showed clear spatial variation of microbial communities in the stomach and intestine, and found that the administration of antibiotics (a mixture of olaquindox, oxytetracycline calcium, kitasamycin) in early life caused markedly differential alterations in the compartmentalized microbiota, with major alterations in their spatial variation in the lumen of the stomach and small intestine. In piglets fed an antibiotic-free diet, most of the variation in microbial communities was concentrated in gut segments and niches (lumen/mucosa). The microbial diversity was higher in the lumen of stomach and duodenum than that in ileum. The early-life antibiotic intervention decreased the abundance of some Lactobacillus species and increased the abundance of potentially pathogenic Streptococcus suis in the lumen of the stomach and small intestine. Interestingly, the intervention increased the abundance of Treponema only in the colonic lumen and that of Faecalibacterium only in the ileal mucosa. Furthermore, the antibiotic intervention exerted location-specific effects on the functional potential involved in the phosphotransferase system (decreased sucrose phosphotransferase in the stomach) and antibiotic-resistance genes (increased in the colon). These results point to an early-life antibiotic-induced dramatic and location-specific shift in the gut microbiota, with profound impact in the foregut and less impact in the hindgut. Collectively, these findings provide new insights into the membership of the microbiota along the gastrointestinal tract of piglets and highlight the importance of considering the foregut microbiota in health management of piglets at early life.