Arizona won the first three games of the series, mostly by coming from behind.

The Brewers prevented the sweep by roughing up Ian Kennedy (3-6) early with a string of two-strike hits and a second straight strong outing by Peralta (7-9)

Carlos Gomez hit a two-run single in the first inning and Jean Segura had three hits for Milwaukee, which ended a six-game losing streak to the Diamondbacks.

Miguel Montero homered for the second straight game, but Kennedy gave up four runs in the first two innings to remain stuck on 49 career wins for the seventh straight start.

Coming off his first complete game shutout, Peralta worked around base runners through the first four innings with the help of two double plays and a pickoff by catcher Martin Maldonado after Adam Eaton strayed too far off first in the third.

The right-hander extended his scoreless streak to 19 1-3 innings until Montero hit his first pitch of the fifth for his eighth homer.

Peralta stranded runners at second and third in the sixth inning and worked around another runner in the seventh. He allowed a run on seven hits and struck out eight.

Kennedy has struggled with his put-away pitches, a big reason he's labored through the first half of the season.

The right-hander again had trouble putting hitters away against the Brewers, allowing four straight singles to open the game - all after getting ahead 0-2 or 1-2.

The fourth one was by Gomez, who lined an 0-2 pitch through the right side for a two-run single and another run came in on a groundout by Maldonado.

Schafer drove in a run with a sacrifice bunt in the second inning and, after falling behind 0-2, led off the fifth inning with a homer that put the Brewers up 5-0.

Kennedy allowed five runs on nine hits in 6 1-3 innings, the second straight start he's allowed five earned runs. He hasn't won since June 1 against the Cubs.

Notes: Arizona 2B Aaron Hill ended a 0-for-16 streak with a single in the fourth inning. ? The Brewers have more than 70 stolen bases (77) before the All-Star break for the first time since swiping 87 bases in 1993. ? Diamondbacks 3B Martin Prado made a pair of diving stops - one in each direction - to take away hits from Maldonado in the first inning and Jeff Bianchi in the sixth. ? Arizona opens the second half of the season at San Francisco on Friday. Milwaukee faces Miami at home the same day.