Yovani Gallardo tossed seven scoreless innings and Aramis Ramirez homered for the fourth time in 10 games as visiting Milwaukee took the rubber match of a three-game series, 4-0.

Jonathan Lucroy had an RBI single and a sacrifice fly and Khris Davis drove in a run with a double for the Brewers, who denied Pittsburgh an opportunity to forge a first-place tie with the St. Louis Cardinals in the National League Central.

The Pirates will be one game behind the Cardinals when the two teams begin a big three-game set Friday at Pittsburgh.

Gallardo (10-9) yielded six hits and a walk while striking out five in his third solid start since coming off the disabled list. Brandon Kintzler worked two hitless innings to finish it off.

Rookie Gerrit Cole (6-7) gave up four runs - three earned - and 10 hits in 7 1/3 frames for the Pirates, losers of four of their last five.

Cole's error helped set up Lucroy's run-scoring hit in the first and Davis' double came with no outs in the second to make it 2-0.

Ramirez drove Cole's second pitch of the fourth inning over the wall in right-center and Lucroy capped the scoring with the sacrifice fly in the eighth to help seal Milwaukee's 75th win in 114 games versus Pittsburgh since 2007.

GAME NOTEBOOK: Pittsburgh C John Buck, acquired Tuesday in a trade with the New York Mets, went 3-for-3 in his debut with the Pirates. ... Gallardo is 2-0 with a 0.93 ERA in three starts since coming off the DL on Aug. 17. ... While Pittsburgh hosts St. Louis, Milwaukee returns home Friday to play the Los Angeles Angels.