PHOENIX The Giants finally got the Matt Cain outing they've been looking for, and it still wasn't enough.
Cain outdueled Arizona ace Patrick Corbin, but the Diamondbacks stormed back in the bottom of the eighth for a 3-1 victory at Chase Field on Friday night.
Cain gave way to Jeremy Affeldt with a 1-0 lead and a runner on first base.
After getting two outs and walking Willie Bloomquist, Affeldt grooved a 2-0 fastball to Paul Goldschmidt. The red-hot first baseman lined a three-run homer over the right-field wall.
"It was a dumb pitch dumb location, dumb selection, stupid," Affeldt said. "I didn't want to throw it there. For a strike pitch it wasn't that bad, but that is not what I am trying to do to him.
"(Goldschmidt) is too hot of a hitter and when you make dumb pitches and you throw to a dumb location they are going to make you look bad. I take full responsibility. The loss is on me. Cain threw really well. He didn't deserve that. It is completely my fault."
Cain entered the night with a 5.45 ERA and nearly got off to another rocky start. The Diamondbacks put two runners on in the first for Goldschmidt, who had 13 RBIs in his previous six games.
Goldschmidt nearly homered twice during the nine-pitch at-bat, hitting deep foul balls just outside of both poles. Cain finally got Goldschmidt to hit into a double play and escaped the inning unscathed despite throwing 31 pitches.
Cain settled in from there, cruising through the next three innings before Didi Gregorius reached third with one out in the fifth. Gregorius took off for home on Corbin's grounder to first and was thrown out by Brandon Belt.
The Giants had not scored since Andres Torres' homer in the second inning Tuesday. But in the seventh, Pablo Sandoval hit a one-out single, took second on Belt's single and then third on Joaquin Arias' fly ball to right. Gregor Blanco hit a first-pitch fastball into center, scoring Sandoval.
Cain allowed four hits in seven innings, giving the Giants exactly what they needed. But this time it was the bullpen that couldn't get the job done.
Notes Leadoff hitter Angel Pagan was placed on the disabled list with a left hamstring strain, and Juan Perez was called up from Triple-A Fresno.
Pagan hurt his hamstring May 25 while playing center field and has not played since ending that game with an inside-the-park home run.
The Associated Press contributed to this report.