PHOENIX -- The Arizona Diamondbacks were relieved to finally get a victory.
Adam Dunn homered with two outs in the bottom of the eighth inning to lead Arizona past the San Francisco Giants 3-1 on Monday night.
"The bottom line is we were shaking hands at the end of the game with a win," Melvin said.
Justin Upton added his 13th home run for the Diamondbacks, who won for just the second time in 10 games to remain 4½ games behind the Los Angeles Dodgers in the NL West.
Arizona is four games back in the loss column with 13 games to play.
"I think we've been watching that (the scoreboard) too much," said Arizona starter Doug Davis, who allowed one unearned run in seven innings. "It makes you press and you try to do too much."
Chris Young led off the eighth with a single to left off Giants starter Brad Hennessey (1-2). The right-hander retired the next two hitters before Dunn hit his first pitch into the second row of the right-field stands.
"The one pitch I needed to cut or keep over the inside part of the plate, I didn't," Hennessey said. "It sucks to lose and to lose that way it's even worse."
It was Dunn's 37th homer overall and fifth since coming to the Diamondbacks on Aug. 11.
"I always put a lot of pressure on myself whether it's baseball or fishing," Dunn said. "I know I need to do better and that's what I'm going to do. You guys can't put more pressure on me. No one can put more pressure on me than me."
Tony Pena (2-2) pitched a perfect eighth inning for the victory and Chad Qualls came on in the ninth for his fourth save in 12 chances.
Hennessey allowed three runs and eight hits over a career-long eight innings with two strikeouts for the Giants, who lost for just the second time in 10 games. Hennessey also hit a batter and saw his career record fall to 0-3 in five starts and 15 appearances against Arizona.
"He pitched a great game," said Giants manager Bruce Bochy. "You give up one run going into the eighth inning in this ball park, you've done a terrific job."
San Francisco took a 1-0 lead in the third. Rich Aurilia singled to center and Bengie Molina followed with a routine fly ball to right-center field. Diamondbacks centerfielder Chris Young sprinted into the gap but dropped the ball while making a nonchalant one-handed catch for a two-base error, scoring Aurilia from first.
The Diamondbacks tied the game when Upton led off the fourth with a 434-foot home run onto the walkway above the centerfield fence, his second home run in three games.
Davis scattered eight hits with two strikeouts. He did not walk a batter for the second time in five starts.
"I was throwing strikes and keeping the ball down," Davis said. "The hits I gave up weren't hit that hard."
The Giants stranded runners on third base in both the fourth and sixth innings and left four runners in scoring position overall.
Hennessey also held Arizona to one run and four hits in six innings in his last start. ... Diamondbacks 1B Josh Whitesell made his first career start and provided one of the season's stranger plays. Pablo Sandoval hit a grounder to third and Mark Reynolds' throw across the diamond drifted to the home-plate side of first. Whitesell made no move to stop Reynolds' throw from going into the Giants dugout but did slap Sandoval in the stomach with his glove as he crossed the first-base bag, leaving the Giants first baseman sprawled in the dirt. Reynolds was charged with the error on the play, his 31st. ... Whitesell recorded his first career hit in the seventh, a bloop single into center off the fists. ... Sandoval is 8-for-22 in the first five games of the Giants' 11-game road trip. ... Young's error snapped an 87-game errorless streak.