Background Lipoatrophy is one of the most feared complications associated with the use of nucleoside or nucleotide reverse transcriptase inhibitors (N[t]RTIs). We aimed to assess soft-tissue changes in participants with HIV who had virological failure of a first-line antiretroviral (ART) regimen containing a non-nucleoside reverse transcriptase inhibitor plus two N(t)RTIs and were randomly assigned to receive a second-line regimen containing a boosted protease inhibitor given with either N(t)RTIs or raltegravir. Methods Of the 37 sites that participated in the randomised, open-label, non-inferiority SECOND-LINE study, eight sites from five countries (Argentina, India, Malaysia, South Africa, and Thailand) participated in the body composition substudy. All sites had a dual energy x-ray absorptiometry (DXA) scanner and all participants enrolled in SECOND-LINE were eligible for inclusion in the substudy. Participants were randomly assigned (1:1), via a computer-generated allocation schedule, to receive either ritonavir-boosted lopinavir plus raltegravir (raltegravir group) or ritonavir-boosted lopinavir plus two or three N(t)RTIs (N[t]RTI group). Randomisation was stratified by site and screening HIV-1 RNA. Participants and investigators were not masked to group assignment, but allocation was concealed until after interventions were assigned. DXA scans were done at weeks 0, 48, and 96. The primary endpoint was mean percentage and absolute change in peripheral limb fat from baseline to week 96. We did intention-to-treat analyses of available data. This substudy is registered with ClinicalTrials.gov, number NCT01513122. Findings Between Aug 1, 2010, and July 10, 2011, we recruited 211 participants into the substudy. The intention-to-treat population comprised 102 participants in the N(t)RTI group and 108 participants in the raltegravir group, of whom 91 and 105 participants, respectively, reached 96 weeks. Mean percentage change in limb fat from baseline to week 96 was 16·8% (SD 32·6) in the N(t)RTI group and 28·0% (37·6) in the raltegravir group (mean difference 10·2%, 95% CI 0·1–20·4; p=0·048). Mean absolute change was 1·04 kg (SD 2·29) in the N(t)RTI group and 1·81 kg (2·50) in the raltegravir group (mean difference 0·6, 95% CI −0·1 to 1·3; p=0·10). Interpretation Our findings suggest that for people with virological failure of a first-line regimen containing efavirenz plus tenofovir and lamivudine or emtricitabine, the WHO-recommended switch to a ritonavir-boosted protease inhibitor plus zidovudine (a thymidine analogue nucleoside reverse transcriptase inhibitor) and lamivudine might come at the cost of peripheral lipoatrophy. Further study could help to define specific groups of people who might benefit from a switch to an N(t)RTI-sparing second-line ART regimen. Funding The Kirby Institute and the Australian National Health and Medical Research Council.