NEW YORK — Rafael Devers hit a tying home run in the ninth inning and Andrew Benintendi singled home the winning run in the 10th as the Boston Red Sox pulled out a 3-2 win over the New York Yankees on Sunday night.

The Red Sox extended their AL East lead over the Yankees to 5 1/2 games after they nearly wasted another brilliant outing by ace Chris Sale, who left after seven innings with the score tied 1-1. The Yankees took the lead in the bottom of the eighth against Matt Barnes on two walks, a single by Aaron Judge and a sacrifice fly to center by Todd Frasier.

But Yankees closer Aroldis Chapman couldn’t protect the lead in the ninth. With two outs, Devers hit a 103 mph fastball over the left-center field fence – only the second home run Chapman has allowed to a left-handed batter in his eight-year career.

Chapman (4-2) stayed in for the 10th but was removed after he hit Jackie Bradley Jr. and walked Eduardo Nunez with one out. Mookie Betts drew a walk from Tommy Kahnle to load the bases, and Benintendi followed with a line drive to right that drove in Bradley.

Red Sox closer Craig Kimbrel (4-0) retired all four batters he faced after he came in with two out and a runner on third in the ninth.

Sale was dominant over the first seven innings, as he struck out 12 and allowed only four hits. But one of those hits was line drive deep to right by Austin Romine that was misplayed by Betts and resulted in a game-tying RBI triple in the fifth inning.

Boston, meanwhile, was held to two hits through eight innings by Jordan Montgomery, David Robertson and Dellin Betances. But the Red Sox pushed across a run in the top of the fifth when Brock Holt walked, took second on a wild pitch and scored on Bradley’s single to left.