Xander Bogaerts of the Red Sox scores on a wild pitch...

Xander Bogaerts of the Red Sox scores on a wild pitch past Jose Trevino of the Yankees during the 11th inning at Yankee Stadium on Friday. Credit: Jim McIsaac

D.J. Reyburn seemed to have done the Yankees a favor.

The plate umpire’s borderline strike call on Matt Carpenter with one on and none out in the ninth inning Friday night prompted a tirade from Aaron Boone, leading to his fifth ejection of the season and his second in the last five games.

The Yankees soon rallied, tying the game when the Red Sox threw away a poor bunt by Isiah Kiner-Falefa.

But after the Yankees squandered excellent chances to win it — bases loaded and none out later in the ninth, followed by bases loaded and one out in the 10th — Michael King’s 0-and-2 wild pitch with two outs in the 11th allowed Xander Bogaerts to score the go-ahead run as the Red Sox won, 5-4, at the Stadium.

“I wouldn’t use the word crushing,’’ Boone said. “We should have won that game. We had our chances and just couldn’t break though. So it’s frustrating.”

In the 11th, ghost runner Bogaerts took third when Alex Verdugo flied out to left for the first out, but he had to hold on Christian Vazquez’s groundout. After Bobby Dalbec swung wildly and missed two sliders, King threw a pitch in the dirt that Jose Trevino couldn’t control. The ball bounced in front of the plate, Trevino went out to get it but dropped it, and Bogaerts scored the go-ahead run after getting a tremendous jump off third base.

Said Trevino, “I could have kept it closer. He [Bogaerts] made a great read on it, but I could have kept it closer.”

The Yankees (62-28) have lost five of six.

It was a classic (though certainly sloppy) Yankees-Red Sox midsummer game throughout, especially in the late innings.

After the Red Sox took a 4-3 lead in the seventh on Dalbec’s leadoff homer off Aroldis Chapman, Garrett Whitlock throttled the Yankees in the seventh and eighth and Tanner Houck came on for the ninth.

Gleyber Torres began the inning with an infield single. Carpenter took a called strike to start his at-bat, which brought Boone several steps out of the dugout to scream at Reyburn, and he was quickly tossed. Boone, gesticulating as he followed Reyburn while the umpire walked in various directions to get away, wound up throwing his gum in frustration.

Boone also was thrown out last Sunday night in Boston after arguing a low strike call on Giancarlo Stanton.

Houck hit Carpenter with a pitch to put two on for Kiner-Falefa, who laid down a too-firm bunt. Houck had an easy play at third but made a wild throw to allow the tying run to score and put runners on second and third with none out. Hicks was intentionally walked, but Trevino grounded into a 5-2-3 double play and DJ LeMahieu grounded softly to Houck.

After Clay Holmes got out of a bases-loaded, two-out jam in the top of the 10th by striking out Bogaerts, the Yankees looked poised to win it in the bottom half. Aaron Judge grounded out but Anthony Rizzo was intentionally walked and Stanton — who hit a three-run homer off Nathan Eovaldi in the third inning to give the Yankees a 3-2 lead — reached on an infield single. That loaded the bases again, but Torres grounded into an inning-ending 4-6-3 double play.

Rafael Devers hit a two-run homer off Jordan Montgomery in the first inning and Christian Vazquez tied the score at 3-3 with a home run in the fourth.

Fortunately for the Yankees, they have not lost any ground of late. After the games of June 18, they were 49-16 and had a 12-game lead over second-place Toronto. They have gone 13-12 since then . . . and now have a 12-game lead over second-place Tampa Bay.

Said Trevino, “A little adversity never hurts anybody. I think we’ll be fine.”

Much of the conversation afterward had to do with Boone’s ejection. Was it the Carpenter pitch in particular? “It was Judge, Rizzo, Carpenter,’’ he said. “Just the balls are low.”

The 6-7 Judge in particular and the 6-6 Stanton repeatedly have been victimized by pitches below their knees being called strikes. Boone has been particularly vociferous about this issue in recent weeks, to no avail. What can he do about it?

“I don’t know,’’ he said. “ I get asked a lot . . .  I don’t know what to tell you guys on this. I mean, we’ve talked to the league. I answer this question every so often. I don’t know what to tell you.”

As of late June, according to Statcast, Judge had dealt with 433 called strikes that have been outside the zone in his career, including 53 balls incorrectly called strikes this season.

Said Judge, “It’s part of the game. I get frustrated in big situations like that, swinging the count a little bit and taking the bat out of my hand, but I can go back to countless at-bats and look at pitches that I missed or fouled off or I should have done some damage on, so I could never solely blame it on a missed call. It’s tough, but it’s part of the game.”

He added of Boone: “I appreciate him standing up for us and kind of speaking our mind and how we’re all feeling. He’s done that quite a bit for us in his career here with us. But like I said, I can look back on a lot of those at-bats tonight that I got a pitch to hit and I missed my pitch and then the pitcher makes a great pitch. It’s part of it. I’ve got to do a better job.”

More Yankees headlines