Brandon Moss hit Pittsburgh's season-high fifth homer of the game leading off the ninth inning and the Pirates won a series against Milwaukee for the first time in nearly two years, rallying to beat the Brewers 8-7 on Wednesday.

The Pirates had lost 17 games in a row to Milwaukee and their previous seven series against the Brewers before taking two of the three, including an 8-5 decision Monday that ended the longest losing streak by one major league team against another in 39 years. Milwaukee won 2-0 on Tuesday.

Ryan Doumit homered twice and Garrett Jones and Andrew McCutchen also went deep _ all three connected in the third inning _ as every Pirates homer was a solo shot. Matt Capps (2-5) got the victory, striking out Casey McGehee with runners on first and third in the top of the ninth.

Moss then hit a 3-1 pitch by Mitch Stetter (2-1) over the center-field wall for his fifth homer.

Jones had three extra-base hits and Delwyn Young went 3 for 4 for the Pirates.

Ryan Braun homered and drove in three runs and McGehee also went deep for Milwaukee, which went 3-4 on a road trip that began in Cincinnati.

The Brewers hoped Jeff Suppan would pitch himself out of a slump against the team he dominates like no other _ he is 13-3 against the Pirates and 6-0 against them with Milwaukee _ but he left trailing 5-2 after giving up four homers in 3 1-3 innings.

Doumit hit his first homer in 33 at-bats since being sidelined 2 1/2 months with a broken wrist, then followed the McCutchen and Jones homers that came a batter apart in the third with his second in a row. That drive was initially ruled a double, but the umpires reversed themselves after watching a video replay that showed Doumit's shot struck a spectator above the home run line in right field and bounced back onto the field. Doumit's homers were his third and fourth of the season.

Suppan, winless in seven starts since June 12, gave up five runs and seven hits.

Pirates starter Paul Maholm, who held the Giants to one unearned run in eight innings Friday, couldn't hold the lead. McGehee hit a two-run homer and Braun added two-run double as Milwaukee went ahead 7-5 in the fifth.

Braun also hit his 18th homer in the first as the two teams combined for seven homers.

The Pirates tied it at 7 in their half of the fifth against Seth McClung on consecutive RBI doubles by Andy LaRoche and Ramon Vazquez. During the game, the Pirates completed the trade that sent LaRoche's older brother, first baseman Adam LaRoche, to Boston for two prospects.

Pittsburgh loaded the bases with one out in the seventh, but Todd Coffey got pinch-hitter Jeff Salazar to ground into a double play. An inning later, Stetter struck out Young with runners on first and second.

NOTES: The Pirates were thin on the bench because of the LaRoche trade and SS Jack Wilson's sore hamstring. ... The Pirates hadn't hit three homers in an inning since July 21, 2008, in the ninth against Houston. ... Milwaukee is 6-2 against Pittsburgh this season.