ImportanceThe Omicron variant is phylogenetically and antigenically distinct from earlier SARS-CoV-2 variants and the original vaccine strain. Protection conferred by prior SARS-CoV-2 infection against Omicron reinfection, with and without vaccination, requires quantification.ObjectiveTo estimate the protection against Omicron reinfection and hospitalization conferred by prior heterologous non-Omicron SARS-CoV-2 infection and/or up to 3 doses of an ancestral, Wuhan-like messenger RNA (mRNA) vaccine.Design, Setting, and ParticipantsThis test-negative, population-based case-control study was conducted between December 26, 2021, and March 12, 2022, and included community-dwelling individuals aged 12 years or older who were tested for SARS-CoV-2 infection in the province of Quebec, Canada.ExposuresPrior laboratory-confirmed SARS-CoV-2 infection with or without mRNA vaccination.Main Outcomes and MeasuresThe main outcome was laboratory-confirmed SARS-CoV-2 reinfection and associated hospitalization, presumed to be associated with the Omicron variant according to genomic surveillance. The odds of prior infection with or without vaccination were compared for case participants with Omicron infection and associated hospitalizations vs test-negative control participants. Estimated protection was derived as 1 − the odds ratio, adjusted for age, sex, testing indication, and epidemiologic week. Analyses were stratified by severity and time since last non-Omicron infection or vaccine dose.ResultsThis study included 696 439 individuals (224 007 case participants and 472 432 control participants); 62.2% and 63.9% were female and 87.4% and 75.5% were aged 18 to 69 years, respectively. Prior non-Omicron SARS-CoV-2 infection was detected for 9505 case participants (4.2%) and 29 712 control participants (6.3%). Among nonvaccinated individuals, prior non-Omicron infection was associated with a 44% reduction (95% CI, 38%-48%) in Omicron reinfection risk, which decreased from 66% (95% CI, 57%-73%) at 3 to 5 months to 35% (95% CI, 21%-47%) at 9 to 11 months postinfection and was below 30% thereafter. The more severe the prior infection, the greater the risk reduction. Estimated protection (95% CI) against Omicron infection was consistently significantly higher among vaccinated individuals with prior infection compared with vaccinated infection-naive individuals, with 65% (63%-67%) vs 20% (16%-24%) for 1 dose, 68% (67%-70%) vs 42% (41%-44%) for 2 doses, and 83% (81%-84%) vs 73% (72%-73%) for 3 doses. For individuals with prior infection, estimated protection (95% CI) against Omicron-associated hospitalization was 81% (66%-89%) and increased to 86% (77%-99%) with 1, 94% (91%-96%) with 2, and 97% (94%-99%) with 3 mRNA vaccine doses, without signs of waning.Conclusions and RelevanceThe findings of this study suggest that vaccination with 2 or 3 mRNA vaccine doses among individuals with prior heterologous SARS-CoV-2 infection provided the greatest protection against Omicron-associated hospitalization. In the context of program goals to prevent severe outcomes and preserve health care system capacity, a third mRNA vaccine dose may add limited protection in twice-vaccinated individuals with prior SARS-CoV-2 infection.