The Padres were trailing 3-0 in the fourth when Chase Headley came through with a run-scoring single and Logan Forsythe added a sacrifice fly.
Jesus Guzman kept the inning alive with a two-out single, putting two men aboard, and Grandal followed by bashing a pitch 442 feet into deep left-center field for the decisive blow.
All five of San Diego's fourth-inning runs were unearned after an error by Arizona shortstop Didi Gregorius had opened the floodgates.
Kyle Blanks also went deep for the fourth-place Padres, who pulled to within three games of National League West-leading Arizona with the series-clinching victory.
Jason Marquis (9-2) ran his unbeaten streak to 10 straight starts, taming the Diamondbacks on three runs over 6 2/3 innings. He overcame four walks and struck out three.
Arizona starter Wade Miley (4-6) was tagged for six runs (one earned) on six hits over six full innings.
Miguel Montero went 2-for-3 with a two-run homer for the D-backs.
2014: The Year in Music [PHOTOS]