Background: Neuroimaging reveals structural brain changes linked with HIV infection and related neurocognitive disorders; however, group-level comparisons between people with HIV and people without HIV do not account for within-group heterogeneity. The aim of this study was to quantify the effects of comorbidities such as cardiovascular disease and adverse social determinants of health on brain ageing in people with HIV and people without HIV., Methods: In this retrospective case-control study, people with HIV from Washington University in St Louis, MO, USA, and people without HIV identified through community organisations or the Research Participant Registry were clinically characterised and underwent 3-Tesla T 1 -weighted MRI between Dec 3, 2008, and Oct 4, 2022. Exclusion criteria were established by a combination of self-reports and medical records. DeepBrainNet, a publicly available machine learning algorithm, was applied to estimate brain-predicted age from MRI for people with HIV and people without HIV. The brain-age gap, defined as the difference between brain-predicted age and true chronological age, was modelled as a function of clinical, comorbid, and social factors by use of linear regression. Variables were first examined singly for associations with brain-age gap, then combined into multivariate models with best-subsets variable selection., Findings: In people with HIV (mean age 44·8 years [SD 15·5]; 78% [296 of 379] male; 69% [260] Black; 78% [295] undetectable viral load), brain-age gap was associated with Framingham cardiovascular risk score (p=0·0034), detectable viral load (>50 copies per mL; p=0·0023), and hepatitis C co-infection (p=0·0065). After variable selection, the final model for people with HIV retained Framingham score, hepatitis C, and added unemployment (p=0·0015). Educational achievement assayed by reading proficiency was linked with reduced brain-age gap (p=0·016) for people without HIV but not for people with HIV, indicating a potential resilience factor. When people with HIV and people without HIV were modelled jointly, selection resulted in a model containing cardiovascular risk (p=0·0039), hepatitis C (p=0·037), Area Deprivation Index (p=0·033), and unemployment (p=0·00010). Male sex (p=0·078) and alcohol use history (p=0·090) were also included in the model but were not individually significant., Interpretation: Our findings indicate that comorbid and social determinants of health are associated with brain ageing in people with HIV, alongside traditional HIV metrics such as viral load and CD4 cell count, suggesting the need for a broadened clinical perspective on healthy ageing with HIV, with additional focus on comorbidities, lifestyle changes, and social factors., Funding: National Institute of Mental Health, National Institute of Nursing Research, and National Institute of Drug Abuse., Competing Interests: Declaration of interests KJP, SAC, FV, JW, JR, TL, and NM have no financial relationships to report. BMA received support for the present work from the National Institutes of Health, the Paula and Rodger Riney Fund, Daniel J Brennan, MD Fund, and participated in a data safety monitoring board for vascular contributions to cognitive impairment and dementia. RP received support from the National Institutes of Health. GMB received support from the National Institutes of Health and the BrightFocus Foundation and participated in a data safety monitoring board for RF1AG061900 - SEABIRD. AS received research support from the National Institutes of Health and the BrightFocus Foundation and has received compensation for serving as a grant reviewer at BrightFocus. AS has a patent issued on “Method and Device for Efficient Parallel Message Computation for Map Inference” and owns equity in TheraPanacea., (Copyright © 2023 Elsevier Ltd. All rights reserved.)