Early-life dietary transitions reflect fundamental aspects of primate evolution and are important determinants of health in contemporary human populations. Weaning is critical to developmental and reproductive rates; early weaning can have detrimental health effects but enables shorter inter-birth intervals, which influences population growth. Uncovering early-life dietary history in fossils is hampered by the absence of prospectively validated biomarkers that are not modified during fossilization. Here we show that large dietary shifts in early life manifest as compositional variations in dental tissues. Teeth from human children and captive macaques, with prospectively recorded diet histories, demonstrate that barium (Ba) distributions accurately reflect dietary transitions from the introduction of mother's milk through the weaning process. We also document dietary transitions in a Middle Palaeolithic juvenile Neanderthal, which shows a pattern of exclusive breastfeeding for seven months, followed by seven months of supplementation. After this point, Ba levels in enamel returned to baseline prenatal levels, indicating an abrupt cessation of breastfeeding at 1.2 years of age. Integration of Ba spatial distributions and histological mapping of tooth formation enables novel studies of the evolution of human life history, dietary ontogeny in wild primates, and human health investigations through accurate reconstructions of breastfeeding history.