Background: Tenofovir disoproxil fumarate can cause renal and bone toxic effects related to high plasma tenofovir concentrations. Tenofovir alafenamide is a novel tenofovir prodrug with a 90% reduction in plasma tenofovir concentrations. Tenofovir alafenamide-containing regimens can have improved renal and bone safety compared with tenofovir disoproxil fumarate-containing regimens. Methods: In these two controlled, double-blind phase 3 studies, we recruited treatment-naive HIV-infected patients with an estimated creatinine clearance of 50 mL per min or higher from 178 outpatient centres in 16 countries. Patients were randomly assigned (1:1) to receive once-daily oral tablets containing 150 mg elvitegravir, 150 mg cobicistat, 200 mg emtricitabine, and 10 mg tenofovir alafenamide (E/C/F/tenofovir alafenamide) or 300 mg tenofovir disoproxil fumarate (E/C/F/tenofovir disoproxil fumarate) with matching placebo. Randomisation was done by a computer-generated allocation sequence (block size 4) and was stratified by HIV-1 RNA, CD4 count, and region (USA or ex-USA). Investigators, patients, study staff, and those assessing outcomes were masked to treatment group. All participants who received one dose of study drug were included in the primary intention-to-treat efficacy and safety analyses. The main outcomes were the proportion of patients with plasma HIV-1 RNA less than 50 copies per mL at week 48 as defined by the the US Food and Drug Adminstration (FDA) snapshot algorithm (pre-specified non-inferiority margin of 12%) and pre-specified renal and bone endpoints at 48 weeks. These studies are registered with ClinicalTrials.gov, numbers NCT01780506 and NCT01797445. Findings: We recruited patients from Jan 22, 2013, to Nov 4, 2013 (2175 screened and 1744 randomly assigned), and gave treatment to 1733 patients (866 given E/C/F/tenofovir alafenamide and 867 given E/C/F/tenofovir disoproxil fumarate). E/C/F/tenofovir alafenamide was non-inferior to E/C/F/tenofovir disoproxil fumarate, with 800 (92%) of 866 patients in the tenofovir alafenamide group and 784 (90%) of 867 patients in the tenofovir disoproxil fumarate group having plasma HIV-1 RNA less than 50 copies per mL (adjusted difference 2·0%, 95% CI -0·7 to 4·7). Patients given E/C/F/tenofovir alafenamide had significantly smaller mean serum creatinine increases than those given E/C/F/tenofovir disoproxil fumarate (0·08 vs 0·12 mg/dL; p<0·0001), significantly less proteinuria (median % change -3 vs 20; p<0·0001), and a significantly smaller decrease in bone mineral density at spine (mean % change -1·30 vs -2·86; p<0·0001) and hip (-0·66 vs -2·95; p<0·0001) at 48 weeks. Interpretation: Through 48 weeks, more than 90% of patients given E/C/F/tenofovir alafenamide or E/C/F/tenofovir disoproxil fumarate had virological success. Renal and bone effects were significantly reduced in patients given E/C/F/tenofovir alafenamide. Although these studies do not have the power to assess clinical safety events such as renal failure and fractures, our data suggest that E/C/F/tenofovir alafenamide will have a favourable long-term renal and bone safety profile. Funding: Gilead Sciences.