San Francisco, CA (Sports Network) - Freddy Sanchez had three hits, knocked in two runs and scored a run to push San Francisco past Arizona, 9-7, in a back and forth affair in the last of a three-game set.
Andres Torres added two hits, two runs scored and drove in two while Jose Guillen's two-run single in the seventh put the Giants ahead to stay as they salvaged the last game of the series to halt a three-game slide.
Jeremy Affeldt (3-3) grabbed the win despite allowing a two-run double that gave Arizona the lead in the top of the seventh, and Brian Wilson recorded the last five outs to earn his 36th save for San Francisco, which moved to within five games of San Diego in the NL West and remained 1 1/2 games behind Wild Card leader Philadelphia.
Esmerling Vasquez (1-5) suffered the loss after yielding three runs -- two earned -- on three hits in his lone inning of work for the Diamondbacks, who had a three-game win streak snapped.
Gerardo Parra singled to start the Arizona seventh, and, after pinch-hitter Rusty Ryal struck out, Giants starting pitcher Matt Cain was lifted with a 5-2 lead in favor of Javier Lopez, who gave up a single to Stephen Drew and was replaced by Santiago Casilla.
The move did not work, as Justin Upton belted a double into centerfield to plate both runners and trim the deficit to a run. Upton moved to third on a wild pitch and stayed put after Kelly Johnson walked and Chris Youngstruck out.
Bruce Bochy turned to Jeremy Affeldt to face LaRoche, and again the percentage play did not pan out, as the left-swinger laced a double to right to chase home both runners to put the visitors in the lead at 6-5.
Vasquez assumed the hill for Arizona in the bottom of the frame and allowed a leadoff single to Sanchez that was followed by a Huff ground rule double that Parra lost in the sun. Guillen then singled into center to chase home both runners to put the Giants back on top at 7-6.
Nate Schierholtz came on as a pinch-runner and advanced to second on an errant pickoff attempt, to third on aPablo Sandoval ground out and scored on a Cody Ross sacrifice fly to push the lead to two.
Parra legged out an infield single to start the eighth and advanced on a Ryan Roberts sacrifice bunt. Drew beat out an infield hit as Parra turned third and headed for the plate. He slid around the attempted tag of catcher Eli Whiteside and beat him back to the plate with a dive to slice the Giants' lead to 8-7.
Wilson then took over on the mound and gave up an infield hit to Upton before Johnson struck out and Young flied out to center to end the threat.
San Francisco added an insurance run in the bottom of the eighth against Juan Gutierrez when Torres walked with two outs and scored on Sandoval's double to right.
Arizona, which struck for six runs in the first inning on Saturday, loaded the bases with one out in the first but Cain bulldogged his way out of the jam by striking out LaRoche and Mark Reynolds.
The visitors did break through two innings later on Drew's leadoff long ball to right.
San Francisco stormed back to grab their first lead of the series in the home half on a run-scoring double by Torres, an RBI single by Sanchez, a Huff fielder's choice grounder that plated Torres and a run-scoring double by Sandoval high off the brick wall in rightfield that brought Huff home to complete the four-run surge.
Eli Whiteside singled with one out in the fourth, moved to second on a Cain single and scored on a Torres base hit to make it a 5-1 contest.
Pinch-hitter Ryan Church struck out to begin the fifth but reached first base on a Cain wild pitch. The right-hander then uncorked two more wild offerings that advanced Church to third, from where he scored on a Drew ground out to cut the deficit to 5-2.
Cain allowed three runs on six hits with a walk and seven strikeouts over 6 1/3 innings...The right-hander had his run of 19 shutout innings against the D'Backs this season snapped in the third inning...Cain is 6-1 in his last 10 home turns and 7-3 in 14 home starts this season...Ross went 0-for-3 and lost an eight-game hitting streak, while Sanchez has hit safely in six straight and is 15-for-24...Giants outfielder Aaron Rowand turned 33 Sunday...Arizona starter Rodrigo Lopez lasted just four frames, giving up five runs on eight hits while walking one and striking out three...LaRoche's two RBI gave him 87, which tied the franchise single-season record for a first baseman, set by Tony Clark in 2005...Arizona is 14-13 with two games left in August, as it tries to secure its first winning month since August of last season.