Ryan Braun scored the tiebreaking run on a wild pitch in the fifth inning.
Gallardo (4-2), who struck out five in a row at one point, has reached double digits in strikeouts in three of his last four starts. He allowed three hits in his fourth straight win but walked Adam LaRoche with the bases loaded.
Gallardo has struck out 35 and allowed only three earned runs over his last 23 innings.
Cole Gillespie hit his first career home run for the Diamondbacks, who were limited to four hits.
Trevor Hoffman pitched the ninth inning for his fifth save in nine attempts.
Gillespie walked with one out in the ninth, but Hoffman got pinch-hitter Justin Upton to ground into a double play to end the game.
Edwin Jackson (1-4) dropped his third straight decision after allowing three runs in seven innings.
It was Jackson's best outing of late — he had given up 18 runs in 6 1-3 innings in his last two starts combined — but he didn't get enough support. He had no one to blame but himself for the deciding run.
Then with two outs and Prince Fielder at-bat, Braun scored on a wild pitch.
Edmonds, who was out of baseball last year after dealing with a variety of injuries the previous three seasons, ended an 0-for-11 skid with his second homer of the year to make it 2-all in the fourth.
Weeks hit a deep drive to left field in the third for the game's first run.
Arizona answered with two runs in the bottom of the inning. Gillespie, a third-round draft pick of the Brewers in 2006, led off with a home run. The Diamondbacks later took their only lead when LaRoche walked with the bases loaded.
NOTES: Brewers CF Carlos Gomez underwent a MRI which revealed a strained left rotator cuff Friday, manager Ken Macha said before the game. He is day to day. Gomez was injured Wednesday against the Dodgers when he went down while attempting to get back to second base during a rundown between second and third. ... Brewers relief pitcher LaTroy Hawkins (0-3), who surrendered Andre Ethier's ninth-inning grand slam Thursday, has a 42.43 ERA in his three losses and a 0.96 ERA in his 10 other appearances.