Goldschmidt, who had a pair of grand slam home runs during the Arizona road trip that ended Thursday, blasted the game-winner on Friday against Jeremy Affeldt (1-2). Goldschmidt raised his league leading RBI total to 57.
With the Giants clinging to a 1-0 lead, San Francisco starter Matt Cain gave up an infield single to A.J. Pollock leading off the ninth.
Cain was then lifted for Affeldt, who retired the first two batters he faced. Affeldt, however, walked Willie Bloomquist and surrendered Goldschmidt's homer on a 2-0 pitch.
Arizona starter Patrick Corbin was trying to become the first pitcher in the majors to record 10 victories, but the Diamondbacks were trailing when he left the game after giving up one run on seven hits in 7 1/3.
Brad Ziegler (3-1) needed just four pitches to retire the final two batters in the eighth and became the winner when Goldschmidt hit his home run.
Heath Bell survived a ninth-inning single to claim his 11th save.
Notable deaths of 2014 [PHOTOS]