© 2019 Elsevier Ltd Background: Research is needed to better understand relations between immunosuppression and HIV viraemia and risk for non-Hodgkin lymphoma, a common cancer in people living with HIV. We aimed to identify key CD4 count and HIV RNA (viral load) predictors of risk for non-Hodgkin lymphoma, overall and by subtype. Methods: We studied people living with HIV during 1996–2014 from 21 Canadian and US cohorts participating in the North American AIDS Cohort Collaboration on Research and Design. To determine key independent predictors of risk for non-Hodgkin lymphoma, we assessed associations with time-updated recent, past, cumulative, and nadir or peak measures of CD4 count and viral load, using demographics-adjusted, cohort-stratified Cox models, and we compared models using Akaike's information criterion. Findings: Of 102 131 people living with HIV during the study period, 712 people developed non-Hodgkin lymphoma. The key independent predictors of risk for overall non-Hodgkin lymphoma were recent CD4 count (ie, lagged by 6 months; <50 cells per μL vs ≥500 cells per μL, hazard ratio [HR] 3·2, 95% CI 2·2–4·7) and average viral load during a 3-year window lagged by 6 months (a cumulative measure; ≥100 000 copies per mL vs ≤500 copies per mL, HR 9·6, 95% CI 6·5–14·0). These measures were also the key predictors of risk for diffuse large B-cell lymphoma (recent CD4 count <50 cells per μL vs ≥500 cells per μL, HR 2·4, 95% CI 1·4–4·2; average viral load ≥100 000 copies per mL vs ≤500 copies per mL, HR 7·5, 95% CI 4·5–12·7). However, recent CD4 count was the sole key predictor of risk for CNS non-Hodgkin lymphoma (<50 cells per μL vs ≥500 cells per μL, HR 426·3, 95% CI 58·1–3126·4), and proportion of time viral load was greater than 500 copies per mL during the 3-year window (a cumulative measure) was the sole key predictor for Burkitt lymphoma (100% vs 0%, HR 41·1, 95% CI 9·1–186·6). Interpretation: Both recent immunosuppression and prolonged HIV viraemia have important independent roles in the development of non-Hodgkin lymphoma, with likely subtype heterogeneity. Early and sustained antiretroviral therapy to decrease HIV replication, dampen B-cell activation, and restore overall immune function is crucial for preventing non-Hodgkin lymphoma. Funding: National Institutes of Health, Centers for Disease Control and Prevention, US Agency for Healthcare Research and Quality, US Health Resources and Services Administration, Canadian Institutes of Health Research, Ontario Ministry of Health and Long Term Care, and the Government of Alberta.