Aim: To investigate the association between morphine exposure in the neonatal period and neurodevelopment at 2 and 5 years of age while controlling for potential confounders. Method: We performed a retrospective, single‐centre cohort study on 106 infants (60 males, 46 females; mean gestational age 26 weeks [SD 1]) born extremely preterm (gestational age < 28 weeks). Morphine administration was expressed as cumulative dose (mg/kg) until term‐equivalent age. Neurodevelopmental outcome was assessed at 2 years with the Bayley Scales of Infant and Toddler Development, Third Edition, Dutch version and at 5 years with the Wechsler Preschool and Primary Scale of Intelligence, Third Edition, Dutch version. Multiple linear regression analysis was used to assess the association between morphine exposure and outcome. Results: Sixty‐four out of 106 (60.4%) infants included in the study received morphine. Morphine exposure was not associated with poorer motor, cognitive, and language subscores of the Bayley Scales of Infant and Toddler Development, Third Edition, Dutch version at 2 years. Morphine exposure was associated with lower Full‐Scale IQ scores (p = 0.008, B = −9.3, 95% confidence interval [CI] = −15.6 to −3.1) and Performance IQ scores (p = 0.005, B = −17.5, 95% CI = −27.9 to −7) at 5 years of age. Interpretation: Morphine exposure in infants born preterm is associated with poorer Full‐Scale IQ and Performance IQ at 5 years. Individualized morphine administration is advised in infants born extremely preterm. What this paper adds: A significant association between morphine exposure and neurodevelopmental impairment at 5 years was observed.Higher exposure to painful and stressful procedures during the neonatal period was associated with poorer abilities at 5 years of age.Differently from previous studies on morphine, this association was also considered in the statistical analysis.A more individualized morphine administration is advised in infants born extremely preterm to counteract the negative effects of high stress without affecting neurodevelopment. [ABSTRACT FROM AUTHOR]