CHICAGO (AP) -- Clint Barmes knew his team needed a lift.
He gave them a spark.
Barmes hit the first of four Houston home runs and the Astros rallied to beat the Chicago Cubs 12-7 on Monday.
Barmes' fifth-inning two-run shot brought Houston within one run, then Hunter Pence followed with a game-tying solo homer as the Astros halted a three-game losing streak.
"We're just staying positive and making things happen," Barmes said. "We're putting stuff together and getting clutch hits in big situations. It was definitely a game that was needed for us."
J.R. Towles gave the Astros the lead with a leadoff home run in the sixth inning off Cubs reliever Jeff Samardzija (3-1). Jeff Keppinger added a three-run shot in the ninth inning to put things out of reach. He finished with three hits and four RBIs.
After blowing leads against the Diamondbacks on Friday and Sunday, the Astros' bullpen only allowed one run over five innings. Astros reliever Sergio Escalona (1-0) pitched one scoreless inning to earn the win.
"With everything that was going on with that game today, to shut them down like they did was impressive," Astros manager Brad Mills said of his bullpen. "Those guys were outstanding."
Game time temperature was in the high-80s and winds were blowing out at almost 20 mph, which is rarely a recipe for low-scoring affairs.
The Astros reached season-highs in runs and home runs, matching their best output this year with 16 hits. They scored 11 runs on 16 hits April 12 against the Cubs in an 11-2 victory in Houston.
"We had good at-bats, ran the bases pretty well," said Pence, who reached base four times and scored three runs. "It's a warm day with the wind blowing out at Wrigley, if you put the ball in a hole there, you have a good chance to find a hit."
Carlos Pena homered run for the Cubs, who committed three errors.
Chicago shortstop Starlin Castro , who committed three errors in an inning earlier this season, made another one in the seventh that allowed a run to score. It was his 10th error of the season.
Trailing 6-3 in the fifth, Michael Bourn tripled off Cubs starter Rodrigo Lopez . Then Barmes and Pence followed with back-to-back shots to left to tie the game at six. It was the first time the Astros hit back-to-back home runs this season.
The Cubs have committed three or more errors eight times this season.
With Casey Coleman ineffective as a replacement starter, Chicago acquired Lopez from Atlanta on Thursday for a minor leaguer and were initially expected to use him as a reliever.
Following Coleman's demotion this weekend, Lopez was made a starter. On Monday, he allowed six runs on 10 hits in 4 2-3 innings.
"(Lopez) was fine," Cubs manager Mike Quade said. "Look, I'm not here to make excuses or anything like that, but it is a tough place to pitch under these conditions. We actually have been dying for these conditions."
Astros starter Aneury Rodriguez only lasted four innings. He allowed six runs, four earned on seven hits.
Cubs outfielder Alfonso Soriano left the game after straining his left quadriceps after trying to beat out a grounder in the first inning.
A few feet from first base, Soriano pulled up holding his left thigh. After limping off the field, Soriano was replaced in left field by Blake DeWitt in the second inning. Soriano will have an MRI.
Notes: Cubs OF Tony Campana stole four bases for the Cubs for the first time since Juan Pierre did it June 15, 2006 for the Cubs against Houston. ... Cubs C Geovany Soto (groin) was back in the lineup after being activated from the disabled list on Sunday. ... The Cubs hope to have RHP Matt Garza back for Sunday's start at St. Louis. ... Pence extended his hitting streak to 11 games.