SummaryBackgroundSouth Africa has a high burden of rifampicin-resistant tuberculosis (including multidrug-resistant [MDR] tuberculosis), with increasing rifampicin-monoresistant (RMR) tuberculosis over time. Resistance acquisition during first-line tuberculosis treatment could be a key contributor to this burden, and HIV might increase the risk of acquiring rifampicin resistance. We assessed whether HIV during previous treatment was associated with RMR tuberculosis and resistance acquisition among a retrospective cohort of patients with MDR or rifampicin-resistant tuberculosis.MethodsIn this retrospective cohort study, we included all patients routinely diagnosed with MDR or rifampicin-resistant tuberculosis in Khayelitsha, Cape Town, South Africa, between Jan 1, 2008, and Dec 31, 2017. Patient-level data were obtained from a prospective database, complemented by data on previous tuberculosis treatment and HIV from a provincial health data exchange. Stored MDR or rifampicin-resistant tuberculosis isolates from patients underwent whole-genome sequencing (WGS). WGS data were used to infer resistance acquisition versus transmission, by identifying genomically unique isolates (single nucleotide polymorphism threshold of five). Logistic regression analyses were used to assess factors associated with RMR tuberculosis and genomic uniqueness.FindingsThe cohort included 2041 patients diagnosed with MDR or rifampicin-resistant tuberculosis between Jan 1, 2008, and Dec 31, 2017; of those, 463 (22·7%) with RMR tuberculosis and 1354 (66·3%) with previous tuberculosis treatment. In previously treated patients, HIV positivity during previous tuberculosis treatment versus HIV negativity (adjusted odds ratio [OR] 2·07, 95% CI 1·35–3·18), and three or more previous tuberculosis treatment episodes versus one (1·96, 1·21–3·17) were associated with RMR tuberculosis. WGS data showing MDR or rifampicin-resistant tuberculosis were available for 1169 patients; 360 (30·8%) isolates were identified as unique. In previously treated patients, RMR tuberculosis versus MDR tuberculosis (adjusted OR 4·96, 3·40–7·23), HIV positivity during previous tuberculosis treatment (1·71, 1·03–2·84), and diagnosis in 2013–17 (1·42, 1·02–1·99) versus 2008–12, were associated with uniqueness. In previously treated patients with RMR tuberculosis, HIV positivity during previous treatment (adjusted OR 5·13, 1·61–16·32) was associated with uniqueness as was female sex (2·50 [1·18–5·26]).InterpretationThese data suggest that HIV contributes to rifampicin-resistance acquisition during first-line tuberculosis treatment and that this might be driving increasing RMR tuberculosis over time. Large-scale prospective cohort studies are required to further quantify this risk.FundingSwiss National Science Foundation, South African National Research Foundation, and Wellcome Trust.