The Phillies needed a win over Houston or a loss by St. Louis to clinch at least a wild-card berth. But the NL East leaders will have to wait to secure their place in the postseason after the Cardinals beat the Pirates 6-4 on Tuesday night.

Philadelphia starter Cole Hamels (14-8) fell to 0-3 in his last five starts against the Astros after going 3-0 in his first four career starts against them.

Happ (6-15), acquired from the Phillies last year as part of the Roy Oswalt trade, allowed four hits and one run with four strikeouts. Fernando Rodriguez threw two scoreless innings before David Carpenter took over for the ninth.

The Astros won their second straight game to avoid setting a franchise record for losses in a season.

In San Francisco, Mark DeRosa hit a game-ending RBI single off second baseman Orlando Hudson’s glove in the 12th inning.

DeRosa’s two-out drive against Brad Bauch (0-2) just evaded Hudson, allowing Cody Ross to score from the third.

Pablo Sandoval and Justin Christian also drove in a run for the Giants, who have won three straight. Ramon Ramirez (3-3) pitched a scoreless inning to get the win.

Jason Bartlett had a two-run double for the Padres, who have lost five of six.

In Los Angeles, Chris Young scored the go-ahead run on a bases-loaded walk in the 10th inning.

Gerardo Parra sparked the Diamondbacks with a tying homer off Hong-Chih Kuo with two out in the seventh, then a leadoff single in the 10th.

After Aaron Hill sacrificed and Justin Upton struck out, Javy Guerra (2-1) issued consecutive walks to Miguel Montero , Paul Goldschmidt and Young, helping Arizona win its second in a row and sixth in seven games.

In Milwaukee, Ryan Braun homered leading off the 11th inning and the Milwaukee Brewers won their sixth straight at home over Colorado.

Prince Fielder also went deep for Milwaukee, which remained 6 1/2 games ahead of second-place St. Louis in the NL Central with 13 to play.

Zack Greinke labored through five innings before the Brewers’ bullpen picked him up. LaTroy Hawkins , Takashi Saito , Francisco Rodriguez, John Axford and Kameron Loe (4-7) combined for six scoreless innings.

Fielder homered in the sixth to tie it and it stayed that way until the 11th, when Braun homered off Matt Lindstrom (2-2) and pumped his right fist in excitement before joining the scrum at home plate.

In Atlanta,   Brian McCann and Dan Uggla each hit a three-run homer and the Atlanta Braves ended their longest losing streak of the season at four games.

The Braves, whose lead over St. Louis in the NL wild-card standings is down to 4 1/2 games, held a private meeting before the game in hopes of shaking things up.

It finally worked in the sixth. Uggla drew a one-out walk from Brad Hand (1-7), Matt Diaz singled to right and McCann came through with a towering shot over the center-field wall for his 24th homer. 

In Pittsburgh, Nick Punto hit a go-ahead double in the ninth inning and the surging St. Louis Cardinals overcame three errors by first baseman Albert Pujols .

Trying to stay in the wild card and NL Central races, the Cardinals won for the sixth time in seven games.

The loss dropped the Pirates to 67-81. In a season that once had so much hope, they are stuck with a non-winning season for the 19th straight year.

In New York, Craig Stammen got his first win and hit in more than a year, scoring the go-ahead run on Ryan Zimmerman’s seventh-inning single.

Stammen (1-1) entered in the sixth with two on, then got three straight outs to escape the trouble. Stammen then singled off Dale Thayer (0-2) leading off seventh — a .217 hitter coming in, Stammen had not gotten a hit since July 30 last year.

Ian Desmond singled him to second with one out, Rick Ankiel advanced Stammen by grounding into a forceout against Tim Bydak, and Zimmerman lined a single to left off Bobby Parnell .

In Cincinnati, Brandon Phillips homered again, hitting a leadoff shot that helped Mike Leake and Cincinnati end a three-game losing streak.

Phillips homered for the third time in two games. He has 15 home runs this year.

Leake (12-9) allowed six hits and two walks over eight innings in what is expected to be his final start of the season. The Reds plan to shut him down in an effort to prevent arm problems.