Whether the sodium–glucose cotransporter 2 inhibitor dapagliflozin reduces the risk of a range of morbidity and mortality outcomes in patients with heart failure regardless of ejection fraction is unknown. A patient-level pooled meta-analysis of two trials testing dapagliflozin in participants with heart failure and different ranges of left ventricular ejection fraction (≤40% and >40%) was pre-specified to examine the effect of treatment on endpoints that neither trial, individually, was powered for and to test the consistency of the effect of dapagliflozin across the range of ejection fractions. The pre-specified endpoints were: death from cardiovascular causes; death from any cause; total hospital admissions for heart failure; and the composite of death from cardiovascular causes, myocardial infarction or stroke (major adverse cardiovascular events (MACEs)). A total of 11,007 participants with a mean ejection fraction of 44% (s.d. 14%) were included. Dapagliflozin reduced the risk of death from cardiovascular causes (hazard ratio (HR) 0.86, 95% confidence interval (CI) 0.76–0.97; P=0.01), death from any cause (HR 0.90, 95% CI 0.82–0.99; P=0.03), total hospital admissions for heart failure (rate ratio 0.71, 95% CI 0.65–0.78; P<0.001) and MACEs (HR 0.90, 95% CI 0.81–1.00; P=0.045). There was no evidence that the effect of dapagliflozin differed by ejection fraction. In a patient-level pooled meta-analysis covering the full range of ejection fractions in patients with heart failure, dapagliflozin reduced the risk of death from cardiovascular causes and hospital admissions for heart failure (PROSPERO: CRD42022346524).