OBJECTIVE: To determine associations of BNT162b2 vaccination with SARS-CoV-2 infection and hospital admission and death with covid-19 among nursing home residents, nursing home staff, and healthcare workers. DESIGN: Prospective cohort study. SETTING: Nursing homes and linked electronic medical record, test, and mortality data in Catalonia on 27 December 2020. PARTICIPANTS: 28 456 nursing home residents, 26 170 nursing home staff, and 61 791 healthcare workers. MAIN OUTCOME MEASURES: Participants were followed until the earliest outcome (confirmed SARS-CoV-2 infection, hospital admission or death with covid-19) or 26 May 2021. Vaccination status was introduced as a time varying exposure, with a 14 day run-in after the first dose. Mixed effects Cox models were fitted to estimate hazard ratios with index month as a fixed effect and adjusted for confounders including sociodemographics, comorbidity, and previous medicine use. RESULTS: Among the nursing home residents, SARS-CoV-2 infection was found in 2482, 411 were admitted to hospital with covid-19, and 450 died with covid-19 during the study period. In parallel, 1828 nursing home staff and 2968 healthcare workers were found to have SARS-CoV-2 infection, but fewer than five were admitted or died with covid-19. The adjusted hazard ratio for SARS-CoV-2 infection after two doses of vaccine was 0.09 (95% confidence interval 0.08 to 0.11) for nursing home residents, 0.20 (0.17 to 0.24) for nursing home staff, and 0.13 (0.11 to 0.16) for healthcare workers. Adjusted hazard ratios for hospital admission and mortality after two doses of vaccine were 0.05 (0.04 to 0.07) and 0.03 (0.02 to 0.04), respectively, for nursing home residents. Nursing home staff and healthcare workers recorded insufficient events for mortality analysis. CONCLUSIONS: Vaccination was associated with 80-91% reduction in SARS-CoV-2 infection in all three cohorts and greater reductions in hospital admissions and mortality among nursing home residents for up to five months. More data are needed on longer term effects of covid-19 vaccines.