Evidence suggests that the SARS-CoV-2 omicron (B.1·1.529) is associated with lower risks of adverse outcomes than the delta (B.1.617.2) variant among the general population. However, little is known about outcomes after omicron infection in pregnancy. We aimed to assess and compare short-term pregnancy outcomes after SARS-CoV-2 delta and omicron infection in pregnancy. We did a national population-based cohort study of women who had SARS-CoV-2 infection in pregnancy between May 17, 2021, and Jan 31, 2022. The primary maternal outcome was admission to critical care within 21 days of infection or death within 28 days of date of infection. Pregnancy outcomes were preterm birth and stillbirth within 28 days of infection. Neonatal outcomes were death within 28 days of birth, and low Apgar score (<7 of 10, for babies born at term) or neonatal SARS-CoV-2 infection in births occurring within 28 days of maternal infection. We used periods when variants were dominant in the general Scottish population, based on 50% or more of cases being S-gene positive (delta variant, from May 17 to Dec 14, 2021) or S-gene negative (omicron variant, from Dec 15, 2021, to Jan 31, 2022) as surrogates for variant infections. Analyses used logistic regression, adjusting for maternal age, deprivation quintile, ethnicity, weeks of gestation, and vaccination status. Sensitivity analyses included restricting the analysis to those with first confirmed SARS-CoV-2 infection and using periods when delta or omicron had 90% or more predominance. Between May 17, 2021, and Jan 31, 2022, there were 9923 SARS-CoV-2 infections in 9823 pregnancies, in 9817 women in Scotland. Compared with infections in the delta-dominant period, SARS-CoV-2 infections in pregnancy in the omicron-dominant period were associated with lower maternal critical care admission risk (0·3% [13 of 4968] vs 1·8% [89 of 4955]; adjusted odds ratio 0·25, 95% CI 0·14-0·44) and lower preterm birth within 28 days of infection (1·8% [37 of 2048] vs 4·2% [98 of 2338]; 0·57, 95% CI 0·38-0·87). There were no maternal deaths within 28 days of infection. Estimates of low Apgar scores were imprecise due to low numbers (5 [1·2%] of 423 with omicron vs 11 [2·1%] of 528 with delta, adjusted odds ratio 0·72, 0·23-2·32). There were fewer stillbirths in the omicron-dominant period than in the delta-dominant period (4·3 [2 of 462] per 1000 births vs 20·3 [13 of 639] per 1000) and no neonatal deaths during the omicron-dominant period (0 [0 of 460] per 1000 births vs 6·3 [4 of 626] per 1000 births), thus numbers were too small to support adjusted analyses. Rates of neonatal infection were low in births within 28 days of maternal SARS-CoV-2 infection, with 11 cases of neonatal SARS-CoV-2 in the delta-dominant period, and 1 case in the omicron-dominant period. Of the 15 stillbirths, 12 occurred in women who had not received two or more doses of COVID-19 vaccination at the time of SARS-CoV-2 infection in pregnancy. All 12 cases of neonatal SARS-CoV-2 infection occurred in women who had not received two or more doses of vaccine at the time of maternal infection. Findings in sensitivity analyses were similar to those in the main analyses. Pregnant women infected with SARS-CoV-2 were substantially less likely to have a preterm birth or maternal critical care admission during the omicron-dominant period than during the delta-dominant period. Wellcome Trust, Tommy's charity, Medical Research Council, UK Research and Innovation, Health Data Research UK, National Core Studies-Data and Connectivity, Public Health Scotland, Scottish Government Health and Social Care, Scottish Government Chief Scientist Office, National Research Scotland.