Yankees starter Masahiro Tanaka allowed four hits in seven shutout innings.

ADAM HUNGER/GETTY IMAGES

Yankees starter Masahiro Tanaka allowed four hits in seven shutout innings.

With the New York Yankees closer to missing out on a wild-card berth than winning the American League East, Masahiro Tanaka pitched like the ace they needed him to be.

Tanaka allowed four hits over seven innings Sunday, and the Yankees defeated the Toronto Blue Jays, 5-0, stopping a five-game losing streak.

Continue reading below

‘‘Today is a great example of what the formula is,’’ Alex Rodriguez said. ‘‘Strong pitching, get the ball to our strong bullpen, and hit the ball out of the park.’’

Dustin Ackley homered and had three RBIs and left fielder Brett Gardner made two excellent catches for the Yankees, who closed back within 3½ games of the AL East-leading Jays with 20 games left.

Toronto had won the first three games of the four-game series, but the Yankees sent R.A. Dickey (10-11) to his first loss since before the All-Star break. The Blue Jays and Yankees play three more times in Toronto Sept. 21-23.

Tanaka (12-6) struck out seven, walked none, and threw 76 of 108 pitches for strikes.

He is 3-0 with a 2.54 ERA in his last four starts.

Astros 5, Angels 3 — Pinch hitter Jed Lowrie hit a three-run homer to complete an astounding five-run rally off Huston Street with two outs in the ninth inning as visiting Houston stunned Los Angeles.

Preston Tucker started the rally with a two-strike solo homer for the Astros, who got five consecutive hits off Street (3-3), the AL saves leader.

George Springer tripled and scored on Jose Altuve’s single before Carlos Correa got an infield single when his hard-hit grounder got stuck in the webbing of second baseman Taylor Featherston’s glove. Lowrie then hit a high fly ball into the short right-field corner, and Kole Calhoun appeared to be inches away from making the catch. The right fielder reached into the crowd and came up empty.

‘‘I just try to be resilient, not give in, and attack,’’ Tanaka said. ‘‘My mind-set was I’m not going to let these guys sweep us.’’

Mets 10, Braves 7 — Daniel Murphy hit a tying three-run homer in the ninth inning, Kirk Nieuwenhuis scored the tiebreaking run on a throwing error in the 10th, and visiting New York won its seventh straight.

Each of the Mets’ final six runs came with two outs. Bobby Parnell (2-3) earned the win, allowing one hit and striking out one in 1 innings. Addison Reed earned his fourth save with a perfect 10th.

Murphy’s 11th homer, coming off Ryan Kelly, made it 7-all.

Facing Edwin Jackson (2-3) in the 10th, Nieuwenhuis scored when Hector Olivera threw errantly to pull Daniel Castro off the bag and let Ruben Tejada beat the tag attempt. New York added a pair of runs on bases-loaded walks.

Nationals 5, Marlins 0 — In Miami, Max Scherzer pitched eight stellar innings to help Washington end a five-game skid.

The Nationals lost star Bryce Harper in the first for precautionary reasons after he collided with Marlins second baseman Derek Dietrich while running the bases.

Harper’s replacement, Matt den Dekker, hit a solo home run, his third of the season.

Anthony Rendon, Jayson Werth, Ian Desmond, and Wilson Ramos also drove in runs for the Nationals, who won the final game of the series after losing the first two.

Scherzer (12-11) allowed five hits and did not walk a batter to earn his first win since July 30.

Orioles 8, Royals 2 — Chris Davis hit his league-leading 42d home run, Jonathan Schoop added a pair of solo shots, and host Baltimore handed Kansas City starter Johnny Cueto (2-6) his fifth straight loss.

The Royals lost seven of nine and dropped their third straight series for the first time this season.

Cardinals 9, Reds 2 — Tommy Pham hit a tiebreaking, two-run homer in the sixth, pinch hitter Matt Adams added a two-run drive in a five-run eighth, and St. Louis avoided a four-game sweep in Cincinnati.

The Cardinals broke open the game in the eighth against Carlos Contreras when a passed ball allowed Kolten Wong to come home from third, and Jason Heyward hit an RBI double and scored on Yadier Molina’s single.

Giants 10, Padres 3 — Mike Leake pitched six strong innings and hit a three-run homer to help host San Francisco complete a three-game sweep.

Buster Posey drove in two runs for the Giants, who have won six of eight. Ehire Adrianza, Marlon Byrd, Angel Pagan, and Matt Duffy also drove in runs. Mike Leake (10-8) won his first game for the Giants since being acquired from the Reds.

Pirates 7, Brewers 6 — Josh Harrison hit a winning single in the 11th inning as host Pittsburgh rallied from a five-run deficit.

With the score 6-6, pinch hitter Travis Ishikawa singled off Tyler Thornburg (0-1) and advanced when left fielder Shane Peterson bobbled the ball for an error. Pinch runner Pedro Florimon moved to third on Jordy Mercer’s ground out, and Sean Rodriguez was hit by a pitch. After a wild pitch advanced Rodriguez, Harrison lined a single to left.

Phillies 7, Cubs 4 — Ryan Howard homered and drove in three runs to help Philadelphia defeat visiting Chicago.

Chris Coghlan had a homer and two triples for the Cubs, who lost two straight to the team with the worst record in the majors.

Dodgers 4, Diamondbacks 3— Zack Greinke pitched eight scoreless innings to lower his major league-leading ERA to 1.61 and help Los Angeles win on the road.

Twins 7, White Sox 0 — Torii Hunter hit a three-run homer and an RBI single and Kyle Gibson won for the third time in four starts against Chicago as visiting Minnesota rolled.

Indians, 7-2; Tigers, 9-2 — J.D. Martinez drove in three runs, and visiting Detroit scored four times in the fourth inning to earn a doubleheader split. Rookie Cody Anderson outpitched Justin Verlander for the second time in a week as Cleveland won the first game.

Rangers 12, Athletics 4 — Adrian Beltre homered twice to drive in five runs, Shin-Soo Choo also went deep, and Texas beat visiting Oakland.

Rockies 3, Mariners 2 — Nolan Arenado hit a sacrifice fly for his 110th RBI of the season, Colorado scored a pair of runs on Kyle Seager’s throwing error, and Colorado defeated host Seattle.