Kendrys Morales homered among his two hits and drove in four runs for the Blue Jays, who won after giving up a three-run lead in the top of the eighth.
Martin then connected for his sixth home run of the season off reliever Jose Alvarado (0-1) over the center-right-field fence in the bottom half.
Roberto Osuna ensured it stood up in the ninth, finally forcing Evan Longoria to pop out to second base to earn his 17th save of the season.
Tampa Bay lost for just the second time in eight games.
Toronto starter Francisco Liriano went seven innings for his longest outing of the season, giving up five hits and two earned runs while striking out nine. The no-decision left him at 99 career wins.
After surrendering two runs in the third, Liriano was on the verge of getting pulled after loading the bases with none out on two walks and a bunt in the fourth inning. However, he escaped the jam, giving up just one run, before retiring the next seven batters in a row.
With the Blue Jays trailing 3-2 in the fifth, Morales hit a three-run shot over the right-field fence into the second deck for his 13th home run of the season and fourth RBI of the game. Morales also had a run-scoring grounder in the third for Toronto's first run.
The home run chased Tampa starter Jake Odorizzi. It marked the ninth consecutive appearance that Odorizzi had allowed a homer, a career high and the second-longest active streak in the majors behind 11 by Jesse Chavez of the Los Angeles Angels.
The Rays had taken the lead in the third inning when Corey Dickerson continued his strong hitting with a two-run triple.
Rays: SS/2B Tim Beckham's knee responded well to treatment, according to Tampa manager Kevin Cash, and is expected to play this weekend in Detroit.
Blue Jays: OF Ezequiel Carrera was placed on the 10-day DL on Wednesday with a fractured right foot. The left fielder suffered fouled a ball off his foot in Tuesday night's loss to the Rays and while X-rays were negative, a CT scan Wednesday showed the fracture. The Jays summoned Dwight Smith Jr. from Triple-A Buffalo to take his place, and he started in left field. . Manager John Gibbons said OF Steve Pearce, out since May 15 with a calf strain, should rejoin the team by the weekend.
Rays: The Rays visit Detroit for a four-game series beginning Thursday, when RHP Alex Cobb (5-5, 4.29) will take on RHP Justin Verlander (4-4, 4.68).
Blue Jays: After a day off, Toronto will open a three-game series against the White Sox on Friday with a matchup between RHP Joe Biagini (1-5, 3.38) and Chicago LHP Jose Quintana (2-8, 5.30).