Background: Margetuximab, a novel, investigational, Fc-engineered, anti-HER2 monoclonal antibody, is designed to more effectively potentiate innate immunity than trastuzumab. We aimed to evaluate the safety, tolerability, and antitumour activity of margetuximab plus pembrolizumab (an anti-PD-1 monoclonal antibody) in previously treated patients with HER2-positive gastro-oesophageal adenocarcinoma. Methods: CP-MGAH22–05 was a single-arm, open-label, phase 1b–2 dose-escalation and cohort expansion study done at 11 academic centres in the USA and Canada and 15 centres in southeast Asia (Korea, Taiwan, and Singapore) that enrolled men and women aged 18 years or older with histologically proven, unresectable, locally advanced or metastatic, HER2-positive, PD-L1-unselected gastro-oesophageal adenocarcinoma, with an Eastern Cooperative Oncology Group performance status of 0 or 1, who had progressed after at least one previous line of therapy with trastuzumab plus chemotherapy in the locally advanced unresectable or metastatic setting. In the dose-escalation phase, nine patients were treated: three received margetuximab 10 mg/kg intravenously plus pembrolizumab 200 mg intravenously every 3 weeks and six received the recommended phase 2 dose of margetuximab 15 mg/kg plus pembrolizumab 200 mg intravenously every 3 weeks. An additional 86 patients were enrolled in the phase 2 cohort expansion and received the recommended phase 2 dose. The primary endpoints were safety and tolerability, assessed in the safety population (patients who received at least one dose of either margetuximab or pembrolizumab) and the objective response rate as assessed by the investigator according to both Response Evaluation Criteria in Solid Tumors (RECIST), version 1.1, in the response-evaluable population (patients with measurable disease at baseline and who received the recommended phase 2 dose of margetuximab and pembrolizumab). This trial is registered with ClinicalTrials.gov, NCT02689284. Recruitment for the trial has completed and follow-up is ongoing. Findings: Between Feb 11, 2016, and Oct 2, 2018, 95 patients were enrolled. Median follow-up was 19·9 months (IQR 10·7–23·1). The combination therapy showed acceptable safety and tolerability; there were no dose-limiting toxicities in the dose-escalation phase. The most common grade 3–4 treatment-related adverse events were anaemia (four [4%]) and infusion-related reactions (three [3%]). Serious treatment-related adverse events were reported in nine (9%) patients. No treatment-related deaths were reported. Objective responses were observed in 17 (18·48%; 95% CI 11·15–27·93) of 92 evaluable patients. Interpretation: These findings serve as proof of concept of synergistic antitumour activity with the combination of an Fc-optimised anti-HER2 agent (margetuximab) along with anti-PD-1 checkpoint blockade (pembrolizumab). Funding: MacroGenics.