Russell Martin hit a tiebreaking two-run homer in the eighth inning to help the Toronto Blue Jays overcome a poor start by 17-game winner J.A. Happ and avoid a three-game sweep by beating the Tampa Bay Rays, 5-3, on Sunday in St. Petersburg, Fla.
The win moved Toronto a game ahead of the Red Sox in the AL East after Boston lost in Oakland.
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.
Happ was up to 85 pitches when he was pulled by manager John Gibbons after Corey Dickerson’s RBI single put the Rays up, 3-1, with two outs in the third.
Five Toronto relievers allowed two hits in 6⅓ scoreless innings.
‘‘That’s a huge job by the bullpen keeping us in the game,’’ Happ said.
Joaquin Benoit (3-1) gave up a single and struck out three in a scoreless seventh.
Roberto Osuna got three outs for his 30th save.
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.
Chris Archer allowed two runs and five hits in 6⅓ innings. He also struck out nine, running his AL-best total to 211.
Yankees 5, Orioles 2 — Chase Headley and Austin Romine had two RBIs apiece, and visiting New York beat Baltimore to avoid a three-game sweep.
After the Yankees were blanked in the first two games of the series, manager Joe Girardi called the finale ‘‘probably the most important game of the year.’’
Although he placed five rookies in the starting lineup, manager Joe Girardi got the victory he needed to keep his young, retooled team in contention for the postseason. New York began the day 4½ games out of the final playoff spot.
Luis Severino (2-8) pitched two strong innings of relief and Dellin Betances, the fifth New York reliever, got four outs for his eighth save.
Angels 4, Mariners 2 — Albert Pujols and C.J. Cron hit back-to-back home runs for visiting Los Angeles in the first inning and six relievers combined to shut down Seattle after starter Matt Shoemaker was hit in the head with a line drive.
Shoemaker was hit on the right side of his head in the second inning on a line drive from Kyle Seager. Shoemaker was able to turn his head slightly to avoid a direct blow to his face but was unable to get his mitt up in time. After the game, the Angels announced that a CT scan revealed Shoemaker suffered a small skull fracture and small hematoma.
Pujols hit his 29th homer of the season off Seattle starter Hisashi Iwakuma (14-11) with two outs in the first and Cron followed with his 15th home run moments later. The Angels hit seven first-inning home runs in the three-game series.
Mets 5, Nationals 1 — Rookie Seth Lugo went seven innings, Curtis Granderson and Jay Bruce each hit a two-run homer, and host New York beat Washington.
The Mets won for the 11th time in 15 tries and stayed within one game of St. Louis for the second NL wild-card slot.
Lugo (3-2) limited the NL East leaders to one run and six hits in seven innings, walking none and striking out four. The 26-year-old righty has won three straight starts, permitting a total of three runs, to help rejuvenate an injury-plagued rotation.
Cardinals 5, Reds 2 — Randal Grichuk and Kolten Wong homered, Carlos Martinez (13-7) carried a shutout into the seventh inning, and visiting St. Louis beat Cincinnati to snap a three-game losing streak.
Yadier Molina had two of the Cardinals’ five hits as they avoided being swept in Cincinnati for the first time since July 2012. St. Louis began the day with a one-game lead over the Mets for the final NL playoff spot. New York was set to host Washington later.
Tigers 6, Royals 5 — Justin Upton hit a two-run homer with two out in the eighth inning, sending Detroit over host Kansas City.
Upton also doubled in J.D. Martinez in the second. He has seven homers and 18 RBIs in his past 14 games. Miguel Cabrera was on first after a leadoff single when Upton drove a fastball from Joakim Soria over the wall in center for his 20th homer, giving Detroit a 6-5 lead. Soria (4-7) blew his fourth save in five opportunities.
Shane Greene (3-3) pitched 1⅓ innings for the win. Francisco Rodriguez worked the ninth for his 38th save in 42 opportunities.
Cubs 3, Giants 2 — Jason Heyward tied it with a single in the ninth inning and his liner to left-center in the 13th won it as host Chicago beat San Francisco to take three of four games in a possible playoff preview.
Anthony Rizzo led off the 13th with a single off Matt Reynolds (0-1) and went to second on Ben Zobrist’s sacrifice. Addison Russell, who had three hits, was walked intentionally before Heyward drove in his third run of the game. Trevor Cahill (4-4) worked a perfect inning in a series in which all four games were decided by one run.
Indians 6, Marlins 5 — Lonnie Chisenhall capped a three-run rally with a two-out RBI single in the ninth inning against Fernando Rodney, helping Cleveland walk off with its sixth straight win.
Chisenhall’s hit dropped in front of a sliding Ichiro Suzuki in right field and scored pinch-runner Michael Martinez. Jose Ramirez’s two-run single — also with two outs — tied it.
Rodney (2-4) allowed three runs, two hits, three walks and threw two wild pitches in two-thirds of an inning.
Dodgers 7, Padres 4 — Jose De Leon struck out nine while winning his major league debut, pinch hitter Yasmani Grandal drove in three runs, including a go-ahead single in the fifth inning, and host Los Angeles rallied to beat San Diego.
De Leon became the 15th different starting pitcher — and seventh in seven days — used by Los Angeles this season. The 24-year-old Puerto Rican, recalled a day earlier from Triple A Oklahoma City, recorded the second-most strikeouts by a Dodgers pitcher in his major league debut.
De Leon (1-0) gave up four runs and six hits in six innings and didn’t issue a walk. The righthander struck out the side in the sixth. Kenley Jansen pitched the ninth to earn his 42d save in 48 chances.
Yasiel Puig hit a three-run homer in the third that put the Dodgers ahead, 3-2, in his second start since being recalled last week after a month-long demotion to the minors. Grandal hit a two-run homer with two outs in the seventh, scoring Puig, who walked, and extending the Dodgers’ lead to 7-4.
Astros 7, Rangers 6 — George Springer and Evan Gattis homered for Houston, which avoided a series sweep and snapped Texas’s seven-game winning streak.
Houston is still 9½ games behind Texas in the AL West with four weeks left in the regular season, and has won only three of 16 games against its division rival this season.
Ken Giles pitched the ninth for his eighth save in 11 chances, the final out coming when the righthander struck out hot-hitting Rougned Odor. Odor had three hits and drove in three runs, including his 29th homer and an RBI single. He homered for the third time in four games and finished the 10-game homestand with six homers and 17 RBIs.
White Sox 13, Twins 11 — Jose Abreu hit two three-run homers and drove in a career-best seven runs, and visiting Chicago used Tim Anderson’s two-run double in the 12th inning to beat Minnesota.
Abreu, Anderson and Melky Cabrera had three hits apiece, helping Chicago overcome four homers for Minnesota. The teams combined for 18 homers while splitting the four-game series.
Juan Minaya (1-0) earned his first major league win. He pitched a scoreless 11th but walked the first two batters in the 12th. Tommy Kahnle then came in and earned his third career save, retiring Eddie Rosario with the bases loaded for the final out.
Byron Buxton hit his first career grand slam for Minnesota, and Brian Dozier, Miguel Sano, and John Ryan Murphy also went deep.
Dozier, who hit his 35th homer, leads the majors with 21 homers since the All-Star break. He has the most home runs of any Twins player since Josh Willingham also hit 35 in 2012. Only Hall of Famer Harmon Killebrew has hit more homers in a single season in Twins history.
Brewers 10, Pirates 0 — Domingo Santana had his first career two-home run game, Jonathan Villar hit his first grand slam, and Chris Carter connected for his 32d homer as Milwaukee swept host Pittsburgh.
The Pirates have lost six in a row since sweeping a four-game series at Milwaukee last weekend, falling 3½ games behind the St. Louis Cardinals for the second National League wild card. The Pirates host the Cardinals in a three-game series beginning Monday.
Diamondbacks 8, Rockies 5 — Socrates Brito snapped a seventh-inning tie with a three-run homer, and visiting Arizona held off Colorado.
Archie Bradley scattered six hits over six innings and Jean Segura had three hits in his return to the lineup for Arizona. Bradley (6-8) struck out six but it appeared he might be the hard-luck loser. Rockies starter Jon Gray (9-7) had allowed a run in the first inning on a sacrifice fly but retired 17 of 19 batters before Arizona roughed him up in the seventh.
Braves 2, Phillies 0 — Julio Teheran pitched six sharp innings, Matt Kemp homered, and visiting Atlanta won its sixth in a row.
Teheran (5-9) allowed five hits and struck out seven while lowering his ERA to 3.01. Jim Johnson worked the ninth for his 15th save, finishing the five-hitter. Kemp hit a leadoff drive in the second for his 28th homer. Freddie Freeman added another leadoff drive in the eighth for his 29th of the year.
Philadelphia dropped its sixth consecutive game, wasting another solid start by Jake Thompson (1-5). The rookie righthander allowed four hits, struck out six and walked four in seven innings.
The loss for the Phillies marked only the fourth time in franchise history that they dropped every game of a homestand of six games or longer. They also did it earlier this season. The other two times were in 1883 and 1964.