Early life is a key period that determines long-term health. Lung development in childhood predicts lung function attained in adulthood and morbidity and mortality across the life course. We aimed to assess the effect of early-life lower respiratory tract infection (LRTI) and associated risk factors on lung development from birth to school age in a South African birth cohort. We prospectively followed children enrolled in a population-based cohort from birth (between March 5, 2012 and March 31, 2015) to age 5 years with annual lung function assessment. Data on multiple early-life exposures, including LRTI, were collected. The effect of early-life risk factors on lung function development from birth to age 5 years was assessed using the Generalised Additive Models for Location, Scale and Shape and Interrupted Time Series approach. 966 children (475 [49·2%] female, 491 [50·8%] male) had lung function measured with oscillometry, tidal flow volume loops, and multiple breath washout. LRTI occurred in 484 (50·1%) children, with a median of 2·0 LRTI episodes (IQR 1·0-3·0) per child. LRTI was independently associated with altered lung function, as evidenced by lower compliance (0·959 [95% CI 0·941-0·978]), higher resistance (1·028 [1·016-1·041]), and higher respiratory rate (1·018 [1·063-1·029]) over 5 years. Additional impact on lung function parameters occurred with each subsequent LRTI. Respiratory syncytial virus (RSV) LRTI was associated with lower expiratory flow ratio (0·97 [0·95-0·99]) compared with non-RSV LRTI. Maternal factors including allergy, smoking, and HIV infection were also associated with altered lung development, as was preterm birth, low birthweight, female sex, and coming from a less wealthy household. Public health interventions targeting LRTI prevention, with RSV a priority, are vital, particularly in low-income and middle-income settings. UK Medical Research Council Grant, The Wellcome Trust, The Bill & Melinda Gates Foundation, US National Institutes of Health Human Heredity and Health in Africa, South African Medical Research Council, Hungarian Scientific Research Fund, and European Respiratory Society.