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.
The Astros won their second straight game to avoid setting a franchise record for losses in a season. Their 97 defeats are tied for the club mark, which has been reached three other times, most recently in 1991.
J.B. Shuck singled in the fourth inning and stole second base before Happ reached on an error by first baseman Ryan Howard with one out. Jason Bourgeois drove in Shuck with a single to put Houston up 2-1 before Barmes' first-pitch homer.
Hunter Pence hit his 20th home run of the season on a ball that bounced high on the wall in left-center to tie it at 1 in the fourth. The former Astro, traded to Philadelphia in July, received a standing ovation from a group of fans sitting near the Phillies dugout.
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.
Carlos Ruiz hit a one-out solo homer off Carpenter to make it 5-2.
The Phillies had a shot to cut the lead in the fifth inning when Jimmy Rollins singled with two outs before Happ walked Placido Polanco and Pence to load the bases. Ryan Howard took Happ to a full count on an eight-pitch at-bat before J.D. Martinez made a leaping catch at the left-field wall to end the inning.
Martinez had an RBI double to give Houston a 1-0 lead in the first inning. Barmes doubled to set up the score. Carlos Lee singled after the double by Martinez, before Matt Downs was hit by a pitch to load the bases with one out.
Hamels escaped the jam by retiring the next two Astros.
Downs looked to have been spiked in the finger when John Mayberry Jr. slid into second base on a double in the second inning. Downs was checked by trainers, but remained in the game.
Downs singled with two outs in the third and reached third on the play on an error by Mayberry when the grounder rolled between his legs in center field. Downs was left stranded when Chris Johnson grounded out to end the inning.
Right fielder Jason Michaels robbed Howard of a hit with a diving catch, which injured his left hand in the second inning. Michaels finished the inning, but was replaced Shuck in the third. The team said Michaels broke a bone in his left hand and would have season-ending surgery to repair the injury later this week.
NOTES: Despite the loss, Philadelphia is 30-10 against lefties this season. ... The teams wrap up the three-game series Wednesday when Houston's Bud Norris faces Philadelphia's Roy Halladay. Halladay allowed just four hits and one run while striking out nine in eight innings in his last start, a 5-3 win over Milwaukee. Norris has won just once in his last 11 starts. ... Lee has hit safely in 21 of his last 22 games.