BOSTON — Aroldis Chapman walked in the winning run without recording an out in the ninth inning, handing the Boston Red Sox a 5-4 win over the New York Yankees on Friday night.

The Yankees’ hard-throwing closer gave up two runs in the ninth for his third blown save. New York entered tied for the major league lead with 17 blown saves.

Mookie Betts and Dustin Pedroia started the rally with consecutive singles and a successful double steal. Betts scored when second baseman Ronald Torreyes booted Xander Bogaerts’ ground ball.

After an intentional walk to Hanley Ramirez, Chapman (2-1) walked Andrew Benintendi on five pitches to bring home Pedroia.

Robby Scott (1-1) got the win for the Red Sox, who got their first victory over the Yankees at home this season. It was Boston’s first game-ending walk since Sept. 23, 2000 against Baltimore.

Gary Sanchez had a two-run home run and an RBI single for the Yankees.

New York, which entered the four-game series 31/2 games behind AL East-leading Boston, had won 4 of the 5 previous meetings against its rival this season.

Drew Pomeranz was on the mound for Boston’s lone victory this season against the Yankees last month in New York. Pomeranz had seven strikeouts Friday, but allowed some pitches to get up in the zone. New York took advantage, scoring three runs in the fifth.

Ramirez put Boston up early, crushing his 14th home run over the left-center field fence in the third.

The Red Sox had a chance to get the lead back with runners on the corners in the seventh, but Benintendi’s long fly ball to center was reeled in on the warning track by Jacoby Ellsbury.

The Yankees struck first, scoring in the third inning. Sanchez hit a hard liner that deflected off Bogaerts’ glove at shortstop and fell into left field, scoring Chase Headley. New York pulled within 3-2 in the fifth on an RBI single by Brett Gardner to set up Sanchez’s go-ahead homer.

NOTES: Red Sox Manager John Farrell said Brock Holt (vertigo) “is close” to returning from the 60-day disabled list. He was slated to DH with Triple-A Pawtucket on Friday and could make a position start there on Saturday.