Saved a bizarre bounce and an obscure rule, the Boston Red Sox staggered Tampa Bay 6-4 Sunday night on a walk-off, two-run homer by Christian Vázquez in the 13th inning to move one victory from eliminating the 100-win Rays from the AL Division Series.

The wild-card Red Sox took a 2-1 edge in the best-of-five matchup, with Game 4 on Monday at Fenway Park — Marathon Day in Boston. Game 5 would be in St. Petersburg, Florida, on Wednesday, if necessary.

Tampa Bay rallied from a 4-2 deficit to tie it in the eighth inning and it was still 4-all when Yandy Diaz singled with one out in the 13th.

Also read: MLB: Urias hits, pitches Dodgers past Giants to even NLDS series

Then came the play that had the umpires scurrying for the rulebook and the Rays scratching their heads.

Kevin Kiermaier lined a two-out shot to right-center that bounced off the short wall in front of the Red Sox bullpen, ricocheted off right fielder Hunter Renfroe’s hip and flew back into the bullpen as Renfroe leaped to try to keep it in play.

It’s a good thing he didn’t: After the umpires conferred and went to the headsets, they correctly awarded Kiermaier a ground rule double and sent Diaz, who had come all the way home, back to third.

Diaz was halfway from second to third and easily would have scored if the ball remained in play. But baseball Rule 5.05(a)(8) states: “Any bounding fair ball is deflected by the fielder into the stands, or over or under a fence on fair or foul territory, in which case the batter and all runners shall be entitled to advance two bases.”

“If I stayed at second, that’s fine,” Kiermaier said. “But I was hoping to see that Yandy scored, because he would have scored obviously. … It’s incredible that it worked out to their advantage just like that.”

Also read: MLB: Max Fried sharp as Braves blank Brewers 3-0 to tie NLDS at 1-1

Rays manager Kevin Cash said he watched the replay and it was obvious Renfroe didn’t knock it over the wall on purpose.

“That’s just the rule. That’s the way it goes. It was very unfortunate for us,” he said. “I think it was fairly obvious that KK or Yandy was going to come around to score, but it didn’t go our way.”

Nick Pivetta struck out Mike Zunino to end the inning, then came bounding off the mound in celebration.

Renfroe walked with one out in the bottom half, then Vázquez hit the first pitch from Luis Patiño over the Green Monster to end it.

Kiké Hernández and Kyle Schwarber each had three hits, including a homer, for Boston.

Hernández singled in the first, singled in the third and homered in the fifth to give him seven consecutive hits in the series. He went 5 for 6 with a home run and three doubles in Boston’s Game 2 win, becoming the first Red Sox player ever with four extra-base hits in a postseason game.

Red Sox ace Nate Eovaldi allowed Austin Meadows’ two-run homer in the top of the first, but Schwarber led off the bottom half with a home run. Hernández’s fifth-inning homer gave Boston a 4-2 lead, but the Rays tied it in the eighth when Wander Franco hit a solo homer and Meadows and Randy Arozarena doubled.

Garrett Whitlock struck out Zunino to end the inning.

Late threats

With a runner on first in the 10th, J.D. Martinez fouled off five pitches with two strikes and then hit one to straightaway center, where Kiermaier pulled it in right in front of the 379 foot marker. (The wind was blowing in.)

In the 11th, Arozarena stole second and was caught in a rundown on his way to third, but he scrambled back to the bag safely. But he was stranded there when Pivetta struck out Zunino and Jordan Luplow to end the inning.

Boston had a runner on first in the 11th when Hernández hit a chopper into the hole between short and third. Franco went to his right to field it, then made a long throw that first baseman Luplow picked out of the dirt for the third out.

Schwarber time

Schwarber, a star of the Cubs’ 2016 World Series title who homered in the wild-card game against the Yankees, also singled and scored in the third, when Boston scored a pair of runs to chase Drew Rasmussen and take a 3-2 lead. He singled in the ninth before leaving for a pinch runner.

But it was Schwarber’s play in the field that endeared him to the Fenway fans.

After earning an error when he lobbed the ball over pitcher Nathan Eovaldi’s head on a grounder in the third inning, Schwarber was tested on a similar play made a more accurate toss in the fourth.

He celebrated by raising both arms in the air and giving a fist pump, then tipping his cap to the cheering fans. Schwarber turned toward the dugout and laughed.

The teams play again on Monday night, with the starters to be announced. Nick Pivetta had been expected to start for Boston and Patiño for the Rays, but both pitched in Game 3. Red Sox manager Alex Cora said it would most likely be Eduardo Rodriguez.