Gallardo (16-8) retired 14 consecutive Pirate batters en route to his eighth straight winning decision, allowing only two hits. The right-hander overcame four walks and struck out six.
Norichika Aoki put the Brewers ahead for good with a first-inning RBI single and added a sacrifice fly in the eighth to cap the scoring for Milwaukee, which came into the contest trailing St. Louis by 2 1/2 games for a National League wild card spot.
Jean Segura added a pair of run-scoring singles and while Carlos Gomez and Jonathan Lucroy each supplied three hits as the Brewers took the opener of a three-game set.
Pittsburgh's A.J. Burnett (15-8) was tagged with the loss, surrendering two runs on seven hits over six full frames.