PHOENIX -- Paul Goldschmidt hit a three-run homer with two outs in the eighth inning and the Arizona Diamondbacks rallied to beat the San Francisco Giants 3-1 on Friday night.
Giants starter Matt Cain pitched into the eighth, departing after A.J. Pollock beat out a grounder to third for an infield single. Jeremy Affeldt retired pinch-hitter Wil Nieves on a grounder to second and struck out Gerardo Parra looking.
But Affeldt (1-2) walked Willie Bloomquist before Goldschmidt lined a 2-0 into the right-field stands for his team-leading 15th home run of the season.
Brad Ziegler (3-1) got the final two outs of the eighth for the victory. Heath Bell pitched a one-hit ninth for his 11th save.
Arizona starter Patrick Corbin took a no-decision in his bid to become the first Diamondbacks pitcher to start a season 10-0, allowing a run and seven hits and striking out four in 7 1/3 innings.
Cain gave up one run and four hits, struck out four and walked three in seven innings. It was only the third time in 13 starts that Cain had allowed one run or fewer.
The Giants broke a scoreless tie in the seventh.
Pablo Sandoval and Brandon Belt started the inning with consecutive singles and Sandoval advanced to third on a fly ball to right, just beating the throw from Parra. Gregor Blanco then lined a single up the middle, scoring Sandoval for the 1-0 lead.
Corbin, who previously beat the Giants on April 13 with 7 1/3 innings of two-run ball, rarely was threatened in the first five innings.
Marco Scutaro singled in the first, Sandoval led off the second with a single and Andres Torres doubled in the third, but all were stranded where they started.
Cain struggled early, giving up a single to Parra to lead off the game and walking three hitters. But Cain used a double-play grounder by Goldschmidt to escape without allowing a run.
The right-hander appeared upset with home-plate umpire Alan Porter's strike zone and yelled back at him as he left the field.
Cain retired nine of the next 10 he faced before Didi Gregorius doubled into the left-field corner leading off the fifth. He then hustled to third on a fly ball to center. Corbin followed with a soft bouncer to first, and Brandon Belt easily threw out Gregorius at home. Parra struck out to preserve the scoreless tie.
NOTES: Cain entered the game 13-6 with a 3.47 ERA in 29 career games against the Diamondbacks. ... Before the game, the Giants placed OF Angel Pagan on the 15-day disabled list with a strained left hamstring and bursitis. They recalled OF Juan Perez from Triple-A. ... First base umpire Jerry Layne left the game in the bottom of the third inning in the middle of an at-bat by Parra. Layne walked first to the Giants' first-base dugout before exiting down the tunnel to the umpires' dressing room. ... Torres' third-inning double was only his eight hit in 51 at-bats on the road this season.