The Diamondbacks produced four runs in both the fifth and sixth innings to break open a tie game and win their third in a row. It was Arizona's 40th victory of the campaign.
Goldschmidt's solo blast touched off Arizona's four-run sixth.
Arizona starter Wade Miley was unable to make it through the fifth. Instead, Will Harris (1-0) came on to record the final out in the fifth and that was enough to bring him the second victory of his career.
Harris has appeared in 35 games with three teams over the last two seasons.
Johnny Cueto (4-1) was roughed up for seven runs on 11 hits in 4 1/3 to take the loss.
Millions of Getty images now available for free via embed tool
Aaron Carter is still in love with Hilary Duff