Philadelphia reduced it magic number to one Tuesday night, thanks to Florida defeating Atlanta.
Elsewhere, Boston, needing only one victory to clinch the AL wild card, lost to Toronto.
Phillies 7, Astros 4 — Pedro Feliz hit a grand slam, J.A. Happ pitched effectively into the sixth inning, and Philadelphia moved closer toward clinching their third straight NL East title.
Happ (12-4) allowed four runs — three earned — and nine hits in 5 2/3 innings, striking out six. He's the first rookie to win 12 games for Philadelphia since Jim Owens in 1959.
Jayson Werth hit a two-run homer and Philadelphia's injury-plagued bullpen tossed 3 1/3 scoreless innings. Jamie Moyer got four outs, and Ryan Madson pitched the last two innings for his 10th save in 16 chances. He allowed two hits in the ninth, but he struck out Carlos Lee on a 96 mph fastball and got Hunter Pence looking to end it.
Madson knocked down Pence with a 97 mph fastball on an 0-2 pitch before freezing him with another 97 mph heater.
Moyer landed awkwardly on his final pitch in the seventh and was helped to the dugout by catcher Paul Bako. Center fielder Shane Victorino made an outstanding, twisting catch on Jeff Keppinger's drive as Moyer watched on his hands and knees. Moyer strained his left groin.
Kazuo Matsui and Lance Berkman homered for the Astros, who won the first five meetings between the teams.
Wilton Lopez (0-1) allowed five runs and six hits in 3 2/3 innings in his first career start. Lopez had made six relief appearances.
Feliz put the Phillies ahead 5-1 in the fourth when he connected off Lopez for his seventh career slam. Ryan Howard started the inning with an infield single and Raul Ibanez followed with a single. After Werth walked to load the bases, Feliz drove the next pitch to the seats in left for his 12th homer.
Marlins 5, Braves 4 — Dan Uggla hit his 31st homer, and Florida snapped the Braves' seven-game winning streak.
Atlanta, which had won eight of 10 and 15 of 17, began the night two games behind NL wild card-leading Colorado with six games left.
Chris Coghlan had three hits and scored twice for the Marlins, who had last three of four. Florida would be eliminated from playoff contention if the Rockies beat Milwaukee later Tuesday.
Blue Jays 8, Red Sox 7 — Adam Lind hit three of Toronto's six homers to lead the Blue Jays, spoiling Boston's hopes of clinching a playoff berth for the second consecutive night.
It was the fifth straight loss for the Red Sox, who would clinch the AL wild-card berth with their next win or the next Texas loss. The Rangers played at the Los Angeles Angels later Tuesday night.
The Red Sox scored five times with two outs in the eighth inning to cut a six-run deficit to 8-7, but Jason Frasor got the last four outs for his 11th save.
Jose Bautista hit the first pitch of the game high over the Green Monster, Aaron Hill singled on the second pitch he saw and then Lind hit a 1-2 pitch from Clay Buchholz to center for another homer. Lyle Overbay walked and scored on Travis Snider's single to give the Blue Jays a 4-0 lead after one-half inning for the second night in a row.
The Blue Jays led 8-2 when Kevin Youkilis hit an RBI double, David Ortiz hit the wall of the Red Sox bullpen for another run-scoring double and J.D. Drew homered over the bullpen to make it a one-run game. Frason relieved Shawn Camp and got Casey Kotchman to pop up to end the inning.
Ricky Romero (13-9) allowed two runs on seven hits and a walk, striking out three in five innings to beat Boston for the first time in five tries this season. He had been 0-3 with an 8.83 ERA against the Red Sox this year.
Buchholz (7-4) allowed seven runs on eight hits — five of them homers — while walking one and striking out four in five innings. He had been 6-0 2.44 ERA in his previous eight starts and had given up just one homer in his previous six starts.
Dustin Pedroia snapped a 1-for-16 skid with two singles and a double. He hit a line drive to the center field warning track with one out and one on in the ninth, then Victor Martinez walked before — with policemen lining up in the aisles in case of a celebration — Youkilis was called out on a 3-2 pitch to end the game.
Yankees 4, Royals 3 — A.J. Burnett pitched well in an encouraging playoff tuneup as New York won its seventh straight.
Little-used Juan Miranda got the game-winning hit off ex-Yankee Kyle Farnsworth (1-5), an infield single that caromed off the reliever's leg and into foul territory between home plate and first base in the ninth.
Miranda raised his arms in jubilation as he crossed the bag and the AL East champions rushed out of the dugout to celebrate as if they'd just won a playoff series.
Following the team's major league-best 15th walk-off win, Burnett pasted Miranda with a whipped cream pie in the face as the rookie was interviewed on television in front of the dugout.