ST. PETERSBURG, Fla. — Manager John Gibbons’ ejection turned into a key moment for the Toronto Blue Jays on Sunday.

Russell Martin hit a tiebreaking two-run homer in the eighth inning to help the Blue Jays overcome a poor start by 17-game winner J.A. Happ and avoid a three-game sweep with a 5-3 win against the Tampa Bay Rays.

Gibbons was ejected by plate umpire Pat Hoberg after Martin struck out in the fourth. When Martin turned a couple times to dispute the call while walking toward the dugout, Gibbons took over the argument from the dugout and got tossed.

“Took the heat for everybody,” Martin said. “I think he kept some guys in the game doing that, including myself.”

Toronto’s victory and Boston’s 1-0 loss at Oakland gave the Blue Jays a one-game lead over the Red Sox for the top spot in the AL East.

Martin hit his 17th homer on a 3-0 pitch from Kevin Jepsen (2-6). He has gone deep nine times and driven in 24 runs over his last 18 games.

“If he’s seeing the ball good, which I thought he was, I gave the approval for him to take a whack at it,” said bench coach DeMarlo Hale, who filled in for Gibbons.

Happ was up to 85 pitches when he was pulled by Gibbons after Corey Dickerson’s RBI single put the Rays up 3-1 with two outs in the third.

Joaquin Benoit (3-1) gave up a single and struck out three in a scoreless seventh. His second strikeout, coming against Evan Longoria, was the 1,000th of his career.

Roberto Osuna got three outs for his 30th save.

Five Toronto relievers allowed two hits in 6 1/3 scoreless innings.

“That’s a huge job by the bullpen keeping us in the game,” Happ said.

Happ has gone fewer than five innings in just two of 27 starts this season, with both coming against Tampa Bay. He allowed eight runs over two innings in a 13-2 loss to the Rays on May 18.

The Blue Jays tied it at 3 in the seventh on Devon Travis’ two-run single off Brad Boxberger, costing 17-game loser Chris Archer a shot at his ninth win.

Archer allowed two runs and five hits in 6 1/3 innings. He also struck out nine, running his AL-best total to 211.

“Their bullpen came in and did a really good job, kept it right there, and our bullpen came in and struggled,” Rays manager Kevin Cash said. “They got hits, they got walks and then the big home run from Russell Martin.”

BENCH NEWS

Blue Jays: OF Melvin Upton Jr., hitting just .185 (20 for 108) against right-handers since the All-Star break, didn’t start with Archer pitching.

Rays: Despite the ability to expand rosters in September, Tampa Bay still had just three position players on the bench on Sunday: C Luke Maile, 1B Logan Morrison and utilityman Nick Franklin. “I think there’s plans to expand,” Cash said.

UP NEXT

Blue Jays: Knuckleballer R.A. Dickey (9-13) and Yankees RHP Masahiro Tanaka (11-4) are Monday’s starters in the first of a three-game set in New York. Toronto is 9-3 against New York this season, including 4-2 at Yankee Stadium.

Rays: RHP Matt Andriese (6-6) will face RHP Ubaldo Jimenez (5-11) and the contending Orioles on Monday in the opener of a three-game home series. Baltimore has won nine of 12 in the season series, but is 3-3 at Tropicana Field.