MILWAUKEE -- The Milwaukee Brewers didn't play their worst game of the season. The outcome sure felt like they had.
Edgar Gonzalez allowed one hit before tiring in the sixth, Brett Wallace, Jason Castro and Jose Altuve all homered, and the Houston Astros beat Yovani Gallardo for the first time in three seasons, dousing the Brewers' faint playoff hopes with a 7-6 victory on Friday night.
"We needed to come back here and play well, and we didn't," Brewers manager Ron Roenicke said.
The biggest culprits were a poor start by Gallardo and a great one by Gonzalez.
"We didn't play well today," Roenicke said. "We didn't pitch well. We gave them a couple of runs in the fourth inning with the defense. We did a nice job coming back, making it interesting with the offense. It just wasn't a well-played game."
The win helped Houston avoid matching their franchise-worst loss total set last season (56-106). It was their first victory since Bo Porter was named as the 17th manager in franchise history on Thursday. His role with Houston begins immediately following his service as the third base coach for the playoff-bound Washington Nationals.
"They went at us with their best pitcher, and we got him today in a big situation," Astros interim manager Tony DeFrancesco said. "They needed to win today. We came in there and snuck one."
The loss practically eliminated the Brewers from contention as Milwaukee fell five games behind St. Louis for the NL's second wild card with five games left for both teams. The Cardinals beat the Nationals 12-2 on Friday.
"Until we're eliminated, we'll keep going at it," Roenicke said.
Milwaukee, 26-10 over its last 36 games, had won the last 11 starts overall by Gallardo (16-9), while the right-hander had beaten Houston 10 straight times, since losing 2-0 at Houston on Aug. 9, 2009.
"I'm just excited that they didn't quit," DeFrancesco said of his team. "They got a chance to knock a team out of the playoffs."
Gallardo struggled, never had a 1-2-3 inning and surrendered two runs in the fourth and fifth innings.
"He wasn't on his game," Roenicke said, adding that Gallardo was already at 75 pitches after four innings. "He just wasn't on all day."
Wallace and Castro hit consecutive home runs in the fifth to push the lead to 5-1. Castro had his first multihomer game with a solo shot off Francisco Rodriguez in the eighth.
The Astros got one run on Dominguez's single in the second and then added two more in the fourth. One run came on shortstop Segura's fielding error. Gonzalez's bunt single drove in the other run. It was his first hit and RBI in eight at-bats this season.
Gonzalez (3-1) was on for the Astros, though.
He allowed Carlos Gomez's 18th home run in the third and then nothing more until Ryan Braun's two-out, two-run double in the sixth. Gonzalez struck out three and did not walk a batter in his fifth start since the Astros purchased his contract from Triple-A Oklahoma City on Sept. 3.
Wilton Lopez struggled through the ninth before picking up his ninth save.
"We've been really confident lately, stayed optimistic," Braun said. "We found a way to win some games late where it certainly didn't look very promising. Tonight looked and felt like it was going to be one of those games."
Gallardo missed a chance to match his career high set last season when he finished 17-10. He allowed eight hits, walked three and struck out five. He has one last opportunity when he starts Wednesday against the San Diego Padres in the season finale.
His one bright spot came in the first inning when he slipped a fastball past Jed Lowrie for a called third strike for his fourth consecutive season with 200 or more strikeouts.
Braun, who leads the NL with 41 home runs, stole his 30th base off reliever Hector Ambriz in the sixth. It marked the second 30-30 season of Braun's career and third in franchise history. Tommy Harper did it in 1970. ... Brewers RHP Wily Peralta underwent an MRI which revealed no problem with his right biceps. He left Thursday's game against Cincinnati after 5 1/3 innings, complaining of tightness. "We didn't like what we saw the first batter he faced (in the sixth)," Roenicke said. Peralta played catch Friday and should throw a bullpen session Saturday. ... Wallace hit his ninth home run and Castro his fourth in the fifth. It was the Astros' fourth time they had hit consecutive home runs this season.