HIV is an independent risk factor for heart failure (HF). However, the association of HIV severity with incident HF and the potential interaction with sex are incompletely understood. Integrated health care system. We conducted a cohort study of people with HIV (PWH) and matched people without HIV (PWoH), all aged ≥ 21 years and with no previous HF. Poisson regression was used to compare incident HF by HIV status, with PWH stratified by severity of HIV infection [defined by recent (<6 months) CD4 count, nadir CD4 count, or recent HIV RNA level]. Models were adjusted for sociodemographic characteristics, substance use, and HF risk factors. Analyses were conducted for men and women combined, then by sex. The study included 38,868 PWH and 386,569 PWoH (mean baseline age = 41.0 ± 10.8 years; 88% men). Compared with PWoH, incident HF risk was higher among PWH with lower recent CD4 [200-499 cells/µL, adjusted rate ratio (aRR) = 1.82, 95% confidence interval (CI) = 1.50 to 2.21 and <200 cells/µL, aRR = 3.26 (2.47 to 4.30)] and a low nadir CD4 [<200 cells/µL, aRR = 1.56 (1.37 to 1.79)] but not among PWH with normal CD4 [≥500 cells/µL, aRR = 1.14 (0.90 to 1.44)]. Higher incident HF risk was observed among PWH at all HIV RNA levels, with greater HF risk at higher HIV RNA levels. The excess HF risk associated with low CD4 (recent or nadir) and high HIV RNA was stronger among women than men (P interactions=0.05, 0.08, and 0.01, respectively). Given the association of HIV severity with HF, optimizing HIV treatment and management may be important for HF prevention among PWH.