The Padres extended their longest winning streak of the season to five games.
Grandal has six career hits since being called up in early June and four of them have been home runs.
Arizona reliever David Hernandez (1-2) retired the first two men he faced in the eighth, but he hit Logan Forsythe with a pitch and Grandal, pinch-hitting for catcher John Baker, hit an 0-2 pitch out to right.
The Padres added two unearned runs in the ninth, one of them on a double by Yonder Alonso. That gave San Diego a four-run lead, which it needed to withstand the two runs allowed in the ninth by Nick Vincent.
Huston Street had to come on to record the final three outs for his 13th save.
Jason Kubel gave Arizona a 3-1 lead with a three-run, first-inning homer.
Swim Week Miami Beach 2014 [PHOTOS]