Aramis Ramirez had three hits including his 350th career home run and drove in four runs as the Milwaukee Brewers edged the Pittsburgh Pirates 7-6 on Tuesday night.

The 16-year veteran third baseman helped stake the Brewers to a 5-0 in the fifth inning but the Pirates rallied to tie it in the sixth. But Milwaukee pulled out the win when rookie pinch-hitter Caleb Gindl hit a tiebreaking sacrifice fly in the eighth inning.

With the game tied 6-6 Rafael Betancourt hit a one-out double off Bryan Morris (5-7) and took third on Scooter Gennett's single. Gindl then lifted a fly to right that scored Betancourt and gave the Brewers their third victory in four games.

Pittsburgh which entered the day one-half game behind St. Louis in the NL Central lost its third in a row.

Milwaukee's Norichka Aoki reached base in all five plate appearances with two singles and three walks. Jonathan Lucroy added three hits and Gennett had two.

Pedro Alvarez went 4-for-4 with a walk and hit his NL-leading 32nd home run for the Pirates. Neil Walker had a three-run homer among his two hits. Andrew McCutchen Andrew Lambo and Felix Pie also had two hits.

Earlier Tuesday the Pirates acquired right fielder Marlon Byrd and catcher John Buck from the New York Mets to bolster an offense that ranks 24th in the major leagues in runs. Both players are expected to join the team on Wednesday.

With the Pirates down by a run McCutchen doubled and Alvarez walked with one out in the ninth but Jim Henderson held on for his 22nd save in 25 opportunities.

Rob Wooten (3-0) allowed Alvarez's homer but pitched 1 1/3 innings for the win.

Both starting pitchers had rough outings. The Brewers' Kyle Lohse gave up five runs and 13 hits in 5 1/3 innings. Pirates All-Star left-hander Jeff Locke was tagged for five runs and eight hits in 4 2/3 innings.

Lohse had been 4-1 with a 2.05 ERA in seven starts since the All-Star break.

Locke's struggles continued as he has allowed 16 runs and 23 hits in 11 1/3 innings in his last three starts. Over his last seven outings he is 0-2 with a 7.02 ERA.

Alvarez tied it 6-6 by lining a solo home run off the right-field foul pole snapping a tie with Arizona's Paul Goldschmidt for the league lead.

Milwaukee had gone ahead by a run in top of the inning when Ramirez lined a two-out RBI double to center that scored Lucroy who had singled.