Aroldis Chapman of the Yankees reacts after Jackie Bradley Jr....

Aroldis Chapman of the Yankees reacts after Jackie Bradley Jr. of the Red Sox scores in the ninth inning tying up the game at Fenway Park on Sunday in Boston. Credit: Getty Images / Adam Glanzman

BOSTON — Worst. Loss. Of. The. Season.

Hands down.

After one of the Yankees’ most stirring and surprising late-inning rallies of the year, closer Aroldis Chapman had an epic ninth-inning meltdown Sunday night, allowing three runs as the Red Sox forced extra innings. Then Boston scored a run in the 10th on Andrew Benintendi’s two-out single and completed a four-game sweep with a 5-4 victory in front of 37,830 delirious fans at Fenway Park.

Afterward, Aaron Boone called it “a tough weekend” — one that began with the Yankees flushing an early 4-0 lead in a 15-7 thrashing Thursday and ended in even more stunning fashion — but one that will not define his club.

“We can’t let this define what’s been a great season for us,” he said. “We will not. We’re too good. This is a test we’re going through, there’s no question. We’re experiencing some adversity, but we’ll also come out on the other side a lot tougher for this.”

Still, the Yankees (68-42) have gone 18-20 in their last 38 games. The Red Sox (79-34) are 29-8 in the same span and have turned a two-game deficit into a 9 1⁄2-game lead.

“It’s a big climb,” Boone said. “But we can’t worry about that right now. We’ve got to right our ship, we have to take care of our business. We’ve got Chicago tomorrow, starting another important series for us.”

That would be against the 41-70 White Sox, but the way things have gone of late, the Yankees aren’t in a position to look past anyone.

And by the way: They lead surging Oakland by 2 1⁄2 games in the race for the first wild card and struggling Seattle by five games in the battle for the second wild card.

With the Yankees holding a 4-1 lead, Chapman began the ninth by striking out Brock Holt looking at a slider but walked Sandy Leon and Mookie Betts to bring the tying run to the plate. Andrew Benintendi, already an established Yankee-killer at 24 years old, struck out looking at a slider, but Steve Pearce — who homered three times Thursday and once Friday — walked on a 3-and-2 pitch. That brought J.D. Martinez (33 homers) to the plate as the potential winning run, and his two-run single made it 4-3 and lifted his RBI total to 93.

With runners on first and second, Xander Bogaerts grounded to third, and when Miguel Andujar’s long throw was in the dirt and Greg Bird couldn’t scoop it, pinch runner Jackie Bradley Jr. scored the tying run.

“I caught it, I wanted to get rid of it quickly and just a bad throw,” Andujar said.

Mitch Moreland struck out to send the game to extra innings. Chapman threw 39 pitches in the ninth, 19 for strikes.

Chapman, who had converted his previous 22 save opportunities but had not appeared since Tuesday, said the long layoff did not affect him. “I can’t use that as an excuse,” he said through his translator. “It’s just a bad outing.”

Jonathan Holder retired the first two batters in the 10th, but Leon singled and went to second on a wild pitch. Betts was intentionally walked and Benintendi grounded a single up the middle to drive in pinch runner Tony Renda with the winning run.

Betts’ 26th homer, a fifth-inning drive off Masahiro Tanaka — who struck out nine in 4 2⁄3 otherwise brilliant innings — gave the Red Sox a 1-0 lead.

David Price, 2-6 with an 8.43 ERA in nine starts against the Yankees since joining Boston, took that lead into the seventh. At that point, the Yankees had gone 9-for-77 at the plate in the past three games and had scored two runs in the past 24 innings.

But Brett Gardner led off with a single and Austin Romine worked an impressive seven-pitch walk. That was all for Price, as Alex Cora brought on righty Heath Hembree to face Shane Robinson. He failed to get a bunt down in a hard-fought at-bat but worked a walk to load the bases.

Aaron Hicks followed with a sharp grounder that went off shortstop Bogaerts’ glove for an error that allowed two runs to score. The Yankees had a 2-1 lead, and their dugout reacted as if they’d earned a walk-off win. The way things had been going, it was understandable.

Giancarlo Stanton, who entered the night 18-for-44 against the Red Sox this season and who already had a first-inning single, ripped an RBI single to left. One out later, Gleyber Torres’ sacrifice fly made it 4-1.

It seemed as if it would end that way — until the ninth.

“This is a weekend we’ll look back on and hopefully be able to say this is one that brought us together and allowed us to grow even more as a club,” Boone said. “I believe in the dudes in that room.”

SUBSCRIBE

Unlimited Digital AccessOnly 25¢for 6 months

ACT NOWSALE ENDS SOON | CANCEL ANYTIME