Microbes colonize all body surfaces at birth and participate in the development of the immune system. In newborn mammals, the intestinal microbiota is first shaped by the dietary and immunological components of milk and then changes upon the introduction of solid food during weaning. Here, we explored the reactivity of the mouse intestinal immune system during the first weeks after birth and into adulthood. At weaning, the intestinal microbiota induced a vigorous immune response-a "weaning reaction"-that was programmed in time. Inhibition of the weaning reaction led to pathological imprinting and increased susceptibility to colitis, allergic inflammation, and cancer later in life. Prevention of this pathological imprinting was associated with the generation of RORγt+ regulatory T cells, which required bacterial and dietary metabolites-short-chain fatty acids and retinoic acid. Thus, the weaning reaction to microbiota is required for immune ontogeny, the perturbation of which leads to increased susceptibility to immunopathologies later in life.