With the score tied 1-1 in the ninth, Padres closer Heath Bell (0-4) fanned Yasiel Puig to begin the frame but then left a 2-2 breaking ball over the plate for Gonzalez, who golfed it into the right-field stands for the go-ahead run.
On the very next pitch, Ramirez lifted a fly ball to right that bounced off the top of the wall for another round-tripper, giving the Dodgers an insurance run.
The blasts made a winner of Brandon League (3-3), who recorded the final out of the eighth inning, and Kenley Jansen struck out two in ninth for his fourth save as the Dodgers earned a split in their four-game series.
Chris Capuano had blanked the Padres on four hits over five innings.
Padres starter Andrew Cashner threw eight innings of one-run ball, yielding five hits and a walk while striking out two.
Carlos Quentin went 2-for-4 with solo homer for San Diego's only run.
Celebrity Families of 2014 [PHOTOS]