Pablo Sandoval backed Madison Bumgarner's 2, in game series.
Bumgarner (10-12) registered a career-high 13 strikeouts and allowed just two runs on seven hits over 8 1/3 innings.
Cody Ross went 3-for-4 with two doubles and two RBI for the Giants, who had lost five of their previous seven, including two straight to the NL West- leading Diamondbacks.
"Of course it starts with Madison; what a job he did out there on the mound," said Giants manager Bruce Bochy. "But we had some big hits from everybody. Of course, Pablo had a big day."
Tim Stauffer (8-12) allowed four runs on seven hits over six innings to suffer the loss.
"Physically and mentally I feel strong and good," Stauffer said. "Just not executing as well as I need to be and as well as I know I'm capable of."
The Giants, who trail the Diamondbacks by seven games, took a 1-0 lead on Sandoval's two-out, first-inning homer.
Bumgarner allowed a runner to reach second in each of the first four innings, but surrendered just one run, which came when Guzman singled after a Jason Bartlett double in the first.
Ross and Brandon Belt singled to place runners on the corners in the second, and Ross crossed the plate on Brandon Crawford's double-play groundout.
Sandoval began the fourth with his 18th homer of the season. Ross doubled two batters later and Crawford made it a 4-1 game with a base hit to right.
Bumgarner retired 12 consecutive batters between a Denorfia one-out double in the fourth and a Bartlett one-out single in the eighth. He began the ninth in search of his first career complete game, but was pulled after allowing a one- out homer to Hundley. Santiago Casilla struck out the next two batters to end the game.
The Giants are 46-9 this season when scoring at least four runs...Bumgarner is 14-2 in his career when receiving three or more runs of support...Sandoval notched the third multi-home run game of his career...Stauffer has lost his last three starts.