Sleep problems associated with poor mental health and academic outcomes may have been exacerbated by the COVID-19 pandemic. To describe sleep in undergraduate students during the COVID-19 pandemic. This longitudinal analysis included data from 9523 students over 4 years (2018-2022), associated with different pandemic phases. Students completed a biannual survey assessing risk factors, mental health symptoms and lifestyle, using validated measures. Sleep was assessed with the Sleep Condition Indicator (SCI-8). Propensity weights and multivariable log-binomial regressions were used to compare sleep in four successive first-year cohorts. Linear mixed-effects models were used to examine changes in sleep over academic semesters and years. There was an overall decrease in average SCI-8 scores, indicating worsening sleep across academic years (average change -0.42 per year; P-trend < 0.001), and an increase in probable insomnia at university entry (range 18.1-29.7%; P-trend < 0.001) before and up to the peak of the pandemic. Sleep improved somewhat in autumn 2021, when restrictions loosened. Students commonly reported daytime sleep problems, including mood, energy, relationships (36-48%) and concentration, productivity, and daytime sleepiness (54-66%). There was a consistent pattern of worsening sleep over the academic year. Probable insomnia was associated with increased cannabis use and passive screen time, and reduced recreation and exercise. Sleep difficulties are common and persistent in students, were amplified by the pandemic and worsen over the academic year. Given the importance of sleep for well-being and academic success, a preventive focus on sleep hygiene, healthy lifestyle and low-intensity sleep interventions seems justified.