Background The standard of care for patients with intermediate-to-high risk renal cell carcinoma is partial or radical nephrectomy followed by surveillance. We aimed to investigate use of nivolumab before nephrectomy followed by adjuvant nivolumab in patients with high-risk renal cell carcinoma to determine recurrence-free survival compared with surgery only. Methods In this open-label, randomised, phase 3 trial (PROSPER EA8143), patients were recruited from 183 community and academic sites across the USA and Canada. Eligible patients were aged 18 years or older with an Eastern Cooperative Oncology Group performance status of 0–1, with previously untreated clinical stage T2 or greater or Tany N+ renal cell carcinoma of clear cell or non-clear cell histology planned for partial or radical nephrectomy. Selected patients with oligometastatic disease, who were disease free at other disease sites within 12 weeks of surgery, were eligible for inclusion. We randomly assigned (1:1) patients using permuted blocks (block size of 4) within stratum (clinical TNM stage) to either nivolumab plus surgery, or surgery only followed by surveillance. In the nivolumab group, nivolumab 480 mg was administered before surgery, followed by nine adjuvant doses. The primary endpoint was investigator-reviewed recurrence-free survival in patients with renal cell carcinoma assessed in all randomly assigned patients regardless of histology. Safety was assessed in all randomly assigned patients who started the assigned protocol treatment. This trial is registered with ClinicalTrials.gov, NCT03055013, and is closed to accrual. Findings Between Feb 2, 2017, and June 2, 2021, 819 patients were randomly assigned to nivolumab plus surgery (404 [49%]) or surgery only (415 [51%]). 366 (91%) of 404 patients assigned to nivolumab plus surgery and 387 (93%) of 415 patients assigned to surgery only group started treatment. Median age was 61 years (IQR 53–69), 248 (30%) of 819 patients were female, 571 (70%) were male, 672 (88%) were White, and 77 (10%) were Hispanic or Latino. The Data and Safety Monitoring Committee stopped the trial at a planned interim analysis (March 25, 2022) because of futility. Median follow-up was 30·4 months (IQR 21·5–42·4) in the nivolumab group and 30·1 months (21·9–41·8) in the surgery only group. 381 (94%) of 404 patients in the nivolumab plus surgery group and 399 (96%) of 415 in the surgery only group had renal cell carcinoma and were included in the recurrence-free survival analysis. As of data cutoff (May 24, 2023), recurrence-free survival was not significantly different between nivolumab (125 [33%] of 381 had recurrence-free survival events) versus surgery only (133 [33%] of 399; hazard ratio 0·94 [95% CI 0·74–1·21]; one-sided p=0·32). The most common treatment-related grade 3–4 adverse events were elevated lipase (17 [5%] of 366 patients in the nivolumab plus surgery group vs none in the surgery only group), anaemia (seven [2%] vs nine [2%]), increased alanine aminotransferase (ten [3%] vs one [<1%]), abdominal pain (four [1%] vs six [2%]), and increased serum amylase (nine [2%] vs none). 177 (48%) patients in the nivolumab plus surgery group and 93 (24%) in the surgery only group had grade 3–5 adverse events due to any cause, the most common of which were anaemia (23 [6%] vs 19 [5%]), hypertension (27 [7%] vs nine [2%]), and elevated lipase (18 [5%] vs six [2%]). 48 (12%) of 404 patients in the nivolumab group and 40 (10%) of 415 in the surgery only group died, of which eight (2%) and three (1%), respectively, were determined to be treatment-related. Interpretation Perioperative nivolumab before nephrectomy followed by adjuvant nivolumab did not improve recurrence-free survival versus surgery only followed by surveillance in patients with high-risk renal cell carcinoma. Funding US National Institutes of Health National Cancer Institute and Bristol Myers Squibb.