BackgroundThe interaction between COVID-19, non-communicable diseases, and chronic infectious diseases such as HIV and tuberculosis is unclear, particularly in low-income and middle-income countries in Africa. South Africa has a national HIV prevalence of 19% among people aged 15–49 years and a tuberculosis prevalence of 0·7% in people of all ages. Using a nationally representative hospital surveillance system in South Africa, we aimed to investigate the factors associated with in-hospital mortality among patients with COVID-19.MethodsIn this cohort study, we used data submitted to DATCOV, a national active hospital surveillance system for COVID-19 hospital admissions, for patients admitted to hospital with laboratory-confirmed SARS-CoV-2 infection between March 5, 2020, and March 27, 2021. Age, sex, race or ethnicity, and comorbidities (hypertension, diabetes, chronic cardiac disease, chronic pulmonary disease and asthma, chronic renal disease, malignancy in the past 5 years, HIV, and past and current tuberculosis) were considered as risk factors for COVID-19-related in-hospital mortality. COVID-19 in-hospital mortality, the main outcome, was defined as a death related to COVID-19 that occurred during the hospital stay and excluded deaths that occurred because of other causes or after discharge from hospital; therefore, only patients with a known in-hospital outcome (died or discharged alive) were included. Chained equation multiple imputation was used to account for missing data and random-effects multivariable logistic regression models were used to assess the role of HIV status and underlying comorbidities on COVID-19 in-hospital mortality.FindingsAmong the 219 265 individuals admitted to hospital with laboratory-confirmed SARS-CoV-2 infection and known in-hospital outcome data, 51 037 (23·3%) died. Most commonly observed comorbidities among individuals with available data were hypertension in 61 098 (37·4%) of 163 350, diabetes in 43 885 (27·4%) of 159 932, and HIV in 13 793 (9·1%) of 151 779. Tuberculosis was reported in 5282 (3·6%) of 146 381 individuals. Increasing age was the strongest predictor of COVID-19 in-hospital mortality. Other factors associated were HIV infection (adjusted odds ratio 1·34, 95% CI 1·27–1·43), past tuberculosis (1·26, 1·15–1·38), current tuberculosis (1·42, 1·22–1·64), and both past and current tuberculosis (1·48, 1·32–1·67) compared with never tuberculosis, as well as other described risk factors for COVID-19, such as male sex; non-White race; underlying hypertension, diabetes, chronic cardiac disease, chronic renal disease, and malignancy in the past 5 years; and treatment in the public health sector. After adjusting for other factors, people with HIV not on antiretroviral therapy (ART; adjusted odds ratio 1·45, 95% CI 1·22–1·72) were more likely to die in hospital than were people with HIV on ART. Among people with HIV, the prevalence of other comorbidities was 29·2% compared with 30·8% among HIV-uninfected individuals. Increasing number of comorbidities was associated with increased COVID-19 in-hospital mortality risk in both people with HIV and HIV-uninfected individuals.InterpretationIndividuals identified as being at high risk of COVID-19 in-hospital mortality (older individuals and those with chronic comorbidities and people with HIV, particularly those not on ART) would benefit from COVID-19 prevention programmes such as vaccine prioritisation as well as early referral and treatment.FundingSouth African National Government.