Gallardo (8-6) gave up four hits, including Andrew McCutchen’s homer in the fourth.
Gallardo struck out two in every inning except the sixth and the side in the seventh.
A.J. Burnett’s nine-game winning streak ended.
McCutchen, who had three of the Pirates’ five hits, hit his 21st homer and fifth in the past four games. He also had two singles. He is batting .560 (28 for 50) with seven homers, 19 runs scored and 16 RBIs in past 12 games and leads the majors with a .371 average.
Gallardo won consecutive starts for the second time this season.
Martin Maldonado went 3 for 4 with one RBI as the Brewers took two of three from the Pirates.
John Axford pitched the ninth for his 16th save.
Burnett (10-3) had his career-high nine-game winning streak ended.
Burnett stranded seven runners in scoring position through five innings, but then gave up four runs and four hits and one error in the sixth.
Nyjer Morgan singled. Ryan Braun singled to right fielder Garrett Jones, whose throw sailed passed the cutoff man and allowed Morgan to score. Braun went to third on the play and scored on Aramis Ramirez’s RBI single.
Burnett allowed four runs and nine hits and struck out seven in seven innings.
NOTES: The last Pittsburgh pitcher to win more than nine straight decisions was Dock Ellis with 13 in 1971. ... Walker extended his hitting streak to 15 games with a single in the first. ... Jeff Bianchi made his Brewers’ debut in the field when he started at shortstop. His contract was selected from Triple-A Nashville on Thursday. He pinch hit on Friday and struck out.