Gallardo (16-8) struck out six and walked four to win his eighth straight decision as Milwaukee moved in front of fading Pittsburgh in the jumbled National League wild-card race. The Brewers remained 2 1/2 games back of the Cardinals, who beat Houston 4-1.
Ryan Braun had two hits, drove in a run and stole three bases for the Brewers, who have won six of seven. Milwaukee's seven stolen bases were the most by the franchise since it moved to the National League in 1998. Carlos Gomez and Jonathan Lucroy had three hits apiece for the Brewers.
A.J. Burnett (15-8) gave up two runs in six innings but couldn't stop Pittsburgh's late season swoon. The Pirates are 4-12 this month.
CARDINALS 4, ASTROS 1
ST. LOUIS (AP) — Kyle Lohse threw seven scoreless innings for his 15th victory and contributed an RBI double as the Cardinals beat the Astros to stay in front for the second NL wild card.
Fernando Abad (0-5) had a career-best six strikeouts in the Astros' 100th loss. They're 8-8 this month under interim manager Tony DeFrancesco and need nine wins in the final 14 games to avoid topping last season's franchise-record 106 losses.
Jon Jay had two hits and two RBIs for the Cardinals, coming off a 2-5 trip but with a favourable upcoming schedule with the next eight against lowly Houston and Chicago. With 14 games to play, the defending World Series champions are 1 1/2 games ahead of the Dodgers.
Lohse (15-3) matched his season best for victories set in 2008 with St. Louis. Jason Motte worked the ninth for his 36th save in 43 chances.
GIANTS 6, ROCKIES 3
SAN FRANCISCO (AP) — Tim Lincecum pitched San Francisco one win closer to an NL West crown as the Giants lowered their magic number to clinch the division to seven.
Lincecum (10-14) struck out six and walked two in 6 1-3 scoreless innings on a day the second-place Los Angeles Dodgers were postponed by rain in Washington.
Marco Scutaro had three singles, drove in a run and scored twice and Xavier Nady had two RBI singles for the Giants (85-63), who moved a season-high 22 games over .500.
Wilin Rosario hit a two-run homer off Santiago Casilla in the eighth inning, matching the Rockies' rookie record of 25 set by Todd Helton in 1998.
Angel Pagan extended his own San Francisco record with an RBI triple in the eighth, his major league-leading 14th.
Jeff Francis (5-6) lost consecutive starts for just the second time all season and his winless stretch reached four outings since he beat the Dodgers on Aug. 27.
MARLINS 4, BRAVES 3, 10 INNINGS
MIAMI (AP) — Jose Reyes hit a two-out RBI single in the 10th inning, and Miami overcame an awful ninth inning to snap Atlanta's four-game winning streak.
With one out in the 10th, pinch-hitter Rob Brantly was walked by Cory Gearrin (0-1), and Gorkys Hernandez was hit by a pitch. Following a strikeout, Reyes hit a blooper that fell in front of a diving Jason Heyward in right field, and Brantly scored without a play.
Atlanta lost to Miami for only the fourth time in 14 meetings.
The Braves rallied from a 3-0 deficit in the ninth to tie the game. Heyward doubled to start the inning against Steve Cishek, and Chipper Jones walked on a 3-2 pitch. With one out, Dan Uggla singled home a run, and Brian McCann followed with a tying two-run double off Mike Dunn.
John Buck hit a two-run homer for Miami. Heath Bell (3-5) pitched a perfect 10th.
REDS 3, CUBS 1
CHICAGO (AP) — Homer Bailey pitched effectively into the eighth inning, Ryan Hanigan hit a three-run double and Cincinnati moved closer to the NL Central title.
The Reds' Dusty Baker managed his 3,000th major league game, and Cincinnati reduced its magic number to four over the Cardinals to clinch the division.
Bailey (12-9) took a two-hit shutout into the eighth before Darwin Barney had his second single of the night and pinch-hitter Bryan LaHair hit an RBI double to make it 3-1. Sean Marshall then came in and hit pinch-hitter Dave Sappelt before getting a strikeout and grounder to end the threat.
Jonathan Broxton worked a perfect ninth for his third save in five chances with Cincinnati, which acquired him in a July 31 deal with Kansas City.
Cubs right-hander Justin Germano (2-8) lost his sixth straight start.
DIAMONDBACKS 3, PADRES 2
PHOENIX (AP) — Ian Kennedy pitched eight innings to earn his 14th victory, Miguel Montero drove in two runs with two doubles and the Diamondbacks finally got a home win against the Padres.
San Diego was 6-0 in Arizona this season before dropping the series opener.
Kennedy (14-11) allowed one run and seven hits. A 21-game winner in 2011, Kennedy is 8-3 in his last 12 starts.
Eric Stults (6-3) gave up three runs and five hits in six innings in his first loss since June 3.
J.J. Putz allowed a run in the ninth on Will Venable's sacrifice fly before finishing for 30th save in 35 opportunities.