Accelerated epigenetic ageing can occur in untreated HIV infection and is partially reversible with effective antiretroviral therapy (ART). We aimed to make a long-term comparison of epigenetic ageing dynamics in people with HIV during untreated HIV infection and during suppressive ART. In this longitudinal study, conducted over 17 years in HIV outpatient clinics in Switzerland, we applied 5 established epigenetic age estimators (epigenetic clocks) in peripheral blood mononuclear cells (PBMCs) in Swiss HIV Cohort Study participants before or during suppressive ART. All participants had a longitudinal set of PBMC samples available at four timepoints (T1-T4). T1 and T2 had to be 3 years or longer apart, as did T3 and T4. We assessed epigenetic age acceleration (EAA) and a novel rate of epigenetic ageing. Between March 13, 1990, and Jan 18, 2018, we recruited 81 people with HIV from the Swiss HIV Cohort Study. We excluded one participant because a sample did not meet quality checks (transmission error). 52 (65%) of 80 patients were men, 76 (95%) were white, and the median patient age was 43 (IQR 37·5-47) years. Per year of untreated HIV infection (median observation 8·08 years, IQR 4·83-11·09), mean EAA was 0·47 years (95% CI 0·37 to 0·57) for Horvath's clock, 0·43 years (0·3 to 0·57) for Hannum's clock, 0·36 years (0·27 to 0·44) for SkinBlood clock, and 0·69 years (0·51 to 0·86) for PhenoAge. Per year of suppressive ART (median observation 9·8 years, IQR 7·2-11), mean EAA was -0·35 years (95% CI -0·44 to -0·27) for Horvath's clock, -0·39 years (-0·50 to -0·27) for Hannum's clock, -0·26 years (-0·33 to -0·18) for SkinBlood clock, and -0·49 years (-0·64 to -0·35) for PhenoAge. Our findings indicate that people with HIV epigenetically aged by a mean of 1·47 years for Horvath's clock, 1·43 years for Hannum's clock, 1·36 years for SkinBlood clock, and 1·69 years for PhenoAge per year of untreated HIV infection; and 0·65 years for Horvath's clock, 0·61 years for Hannum's clock, 0·74 years for SkinBlood clock, and 0·51 years for PhenoAge, per year of suppressive ART. GrimAge showed some change in the mean EAA during untreated HIV infection (0·10 years, 0·02 to 0·19) and suppressive ART (-0·05 years, -0·12 to 0·02). We obtained very similar results using the rate of epigenetic ageing. Contribution of multiple HIV-related, antiretroviral, and immunological variables, and of a DNA methylation-associated polygenic risk score to EAA was small. In a longitudinal study over more than 17 years, epigenetic ageing accelerated during untreated HIV infection and decelerated during suppressive ART, highlighting the importance of limiting the duration of untreated HIV infection. Swiss HIV Cohort Study, Swiss National Science Foundation, and Gilead Sciences.