The Pirates had to turn to their bull pen in the first inning when starter Jeff Karstens suffered a hip strain.
Karstens (5-4) retired only one batter while giving up four runs on five hits -- including Hart's two-run blast. Milwaukee eventually pounded out 15 hits against five Pittsburgh pitchers.
The Brewers broke things open with a four-run eighth that included the two-run homer by Ramirez.
Mark Rogers (3-1) lasted 5 1/3 innings to get the win. In his seventh start of the season, Rogers allowed a run on five hits with five strikeouts.