PHOENIX -- Wily Peralta had trouble keeping the ball down in the second inning and Arizona took advantage, lining one hit after another.
The right-hander started hitting his spots after that, setting up Milwaukee for a big finish.
Peralta pitched seven effective innings, Aramis Ramirez lined a two-run double in the eighth inning and the Brewers broke open a close game late for a 9-3 victory over the Diamondbacks on Monday night.
"In that second inning, I was missing pitches, missing location," Peralta said. "After that, I just got into a rhythm."
Peralta (7-5) shook off that shaky inning to keep the NL Central-leading Brewers close against Arizona and Brandon McCarthy.
Milwaukee ran away with it once McCarthy left, scoring three runs in the eighth against Will Harris (0-2): two on Ramirez's third hit and another on a run-scoring single by Khris Davis.
Ryan Braun hit a two-run triple off J.J. Putz in the ninth inning and Scooter Gennett had a run-scoring single after homering earlier in the game for the Brewers, who had 12 hits.
"We swung the ball really well throughout the game," Brewers manager Ron Roenicke said. "There were a couple of chances early where we could have broken the game open."
McCarthy gave the Diamondbacks a chance, shaking off his own early troubles to go seven innings. He helped himself out, too, slashing a two-run single in the second inning.
Arizona's bullpen, which has been solid recently, couldn't hold it. Harris gave up the three runs with two outs in the ninth and the Brewers kept hitting from there, sending Arizona to its fifth loss in six games.
"We had it set up pretty good right there, but it didn't work out," said Arizona manager Kirk Gibson, who was ejected in the ninth inning after a review failed to overturn a stolen base call at third base. "Two outs and to score all those runs, it didn't work out the way it wanted to."
Both starters had some rough moments before settling down.
Peralta appeared to be back on track in his last start after two shaky outings, holding the New York Mets to a run over 6 2-3 innings.
The hard-throwing right-hander didn't keep the momentum rolling early against the Diamondbacks, giving up five hits in Arizona's three-run second inning.
Roger Kieschnick had a run-scoring single in in his first at-bat after being called up to replace Bronson Arroyo, who was placed on the disabled list for the first time in his career due to a sore elbow.
McCarthy, a .125 hitter this season, followed with a jam-shot single to right, driving in two more runs to put Arizona up 3-2.
Peralta was sharp after that, retiring 10 straight batters until Kieschnick lined a leadoff single in the seventh. Arizona got two on against him, but Peralta hustled to first base to complete an inning-ending double play.
He allowed three runs and nine hits and struck out six.
"I still thought he fought it, was still up in the zone too much," Roenicke said. "We've got to get him down in the zone, try to get some easy outs. He's working so hard out there to get outs."
McCarthy gave up five runs in his last start and appeared to be headed toward another shaky outing. He gave up two runs in the second inning and a leadoff homer by Gennett in the third, the 15th he has allowed this season.
McCarthy retired 13 of the next 14 batters he faced, though, and was helped along by three double plays.
Left fielder Gerardo Parra had the best of the bunch in the third inning, diving to rob Ramirez of a hit and throwing out Braun at second after he thought the ball was going to fall for a hit. Second baseman Aaron Hill also made diving stop up the middle to get Mark Reynolds in the seventh inning.
McCarthy came out to start the eighth, but was lifted when the Brewers sent up a left-handed pinch-hitter. He allowed three runs and seven hits.
"Back in a good place. I started attacking more and trying to do everything I could to keep us in it and go as deep as I could," McCarthy said.
NOTES: A moment of silence was held before the game to honour Hall of Famer Tony Gwynn, who died Monday from cancer at 54. ... The Brewers started Elian Herrera in centre field to give Carlos Gomez a night off. Gomez has reached base in 30 straight games. ... Arizona's Paul Goldschmidt extended his hitting streak to 10 games with a single in the first inning. ... Arizona LHP Wade Miley will start Tuesday in the second game of the series against RHP Kyle Lohse.