Immunocompromised patients may be at higher risk of mortality if hospitalised with Coronavirus Disease 2019 (COVID-19) compared with immunocompetent patients. However, previous studies have been contradictory. We aimed to determine whether immunocompromised patients were at greater risk of in-hospital death and how this risk changed over the pandemic. We included patients > = 19 years with symptomatic community-acquired COVID-19 recruited to the ISARIC WHO Clinical Characterisation Protocol UK prospective cohort study. We defined immunocompromise as immunosuppressant medication preadmission, cancer treatment, organ transplant, HIV, or congenital immunodeficiency. We used logistic regression to compare the risk of death in both groups, adjusting for age, sex, deprivation, ethnicity, vaccination, and comorbidities. We used Bayesian logistic regression to explore mortality over time. Between 17 January 2020 and 28 February 2022, we recruited 156,552 eligible patients, of whom 21,954 (14%) were immunocompromised. In total, 29% (n = 6,499) of immunocompromised and 21% (n = 28,608) of immunocompetent patients died in hospital. The odds of in-hospital mortality were elevated for immunocompromised patients (adjusted OR 1.44, 95% CI [1.39, 1.50], p < 0.001). Not all immunocompromising conditions had the same risk, for example, patients on active cancer treatment were less likely to have their care escalated to intensive care (adjusted OR 0.77, 95% CI [0.7, 0.85], p < 0.001) or ventilation (adjusted OR 0.65, 95% CI [0.56, 0.76], p < 0.001). However, cancer patients were more likely to die (adjusted OR 2.0, 95% CI [1.87, 2.15], p < 0.001). Analyses were adjusted for age, sex, socioeconomic deprivation, comorbidities, and vaccination status. As the pandemic progressed, in-hospital mortality reduced more slowly for immunocompromised patients than for immunocompetent patients. This was particularly evident with increasing age: the probability of the reduction in hospital mortality being less for immunocompromised patients aged 50 to 69 years was 88% for men and 83% for women, and for those >80 years was 99% for men and 98% for women. The study is limited by a lack of detailed drug data prior to admission, including steroid doses, meaning that we may have incorrectly categorised some immunocompromised patients as immunocompetent. Immunocompromised patients remain at elevated risk of death from COVID-19. Targeted measures such as additional vaccine doses, monoclonal antibodies, and nonpharmaceutical preventive interventions should be continually encouraged for this patient group. ISRCTN 66726260.