Neonates are protected from colonizing bacteria by antibodies secreted into maternal milk. Necrotizing enterocolitis (NEC) is a disease of neonatal preterm infants with high morbidity and mortality that is associated with intestinal inflammation driven by the microbiota1–3. The incidence of NEC is substantially lower in infants fed with maternal milk, although the mechanisms that underlie this benefit are not clear4–6. Here we show that maternal immunoglobulin A (IgA) is an important factor for protection against NEC. Analysis of IgA binding to fecal bacteria from preterm infants indicated that maternal milk was the predominant source of IgA in the first month of life and that a relative decrease in IgA-bound bacteria is associated with the development of NEC. Sequencing of IgA-bound and unbound bacteria revealed that before the onset of disease, NEC was associated with increasing domination by Enterobacteriaceae in the IgA-unbound fraction of the microbiota. Furthermore, we confirmed that IgA is critical for preventing NEC in a mouse model, in which pups that are reared by IgA-deficient mothers are susceptible to disease despite exposure to maternal milk. Our findings show that maternal IgA shapes the host–microbiota relationship of preterm neonates and that IgA in maternal milk is a critical and necessary factor for the prevention of NEC.