Altogether, 20-30% of women receive intrapartum antibiotic prophylaxis (IAP) to prevent sepsis in infants and 2-5% of newborn infants receive antibiotics due to suspected sepsis. Caesarean section has a long-term impact on the intestinal microbiome but the effects of perinatal antibiotics on gut microbiome in vaginally delivered infants are not well known. We compared the impact of IAP, postnatal antibiotics, or their combination on the gut microbiome and emergence of antimicrobial resistance in a controlled study of 149 newborn infants recruited within 24 hours after birth. We collected 659 fecal samples, including 426 daily samples from infants before discharge from the hospital and 111 follow-up samples at six months. Penicillin was mostly used for IAP and the combination of penicillin and aminoglycoside for postnatal treatment. Postnatal antibiotic groups received Lactobacillus reuteri probiotic. Newborn gut colonization differed in both IAP and postnatal antibiotics groups as compared to that in control group. The effect size of IAP was comparable to that caused by postnatal antibiotics. The observed differences were still present at six months and not prevented by lactobacilli consumption. Given the present clinical results, the impact of perinatal antibiotics on the subsequent health of newborn infants should be further evaluated.