Background Data on immune checkpoint inhibitor efficacy in patients with human epidermal growth factor receptor 2-positive (HER2+) advanced gastric/gastroesophageal junction (G/GEJ) cancer are lacking. Because HER2 status was not captured in the ATT RAC TION-2 trial, we used patients with prior trastuzumab use (Tmab+) as surrogate for HER2 expression status to evaluate the efficacy and safety of nivolumab as third-or later-line therapy in these patients. Methods In ATT RAC TION-2, a randomized, double-blind, placebo-controlled, phase 3 multicenter trial, patients were randomized (2:1) to receive nivolumab (3 mg/kg) or placebo every 2 weeks until disease progression or toxicity requiring study discontinuation. Overall survival (OS), progression-free survival (PFS), objective response rate (ORR), and safety were assessed. Results Of 493 enrolled patients, 81 (nivolumab, n = 59; placebo, n = 22) were Tmab+ and 412 (nivolumab, n = 271; placebo, n = 141) were Tmab−. In both groups, patients receiving nivolumab showed a longer median OS vs placebo (Tmab+, 8.3 [95% confidence interval, 5.3-12.9] vs 3.1 [1.9-5.3] months, hazard ratio, 0.38 [0.22-0.66]; P = 0.0006; Tmab−, 4.8 [4.1-6.0] vs 4.2 [3.6-4.9] months, 0.71 [0.57-0.88]; P = 0.0022). PFS was longer in both groups receiving nivolumab vs placebo (Tmab+,.0] vs 1.5 [1.3-2.9] months, 0.49 [0.29-0.85]; P = 0.0111; Tmab−, 1.6 [1.5-2.4] vs 1.5 [1.5-1.5] months, 0.64 [0.51-0.80]; P = 0.0001). Conclusions Nivolumab was efficacious and safe as third-or later-line therapy regardless of prior trastuzumab use in patients with advanced G/GEJ cancer.