The Padres captured their fifth straight, equaling their longest winning streak of the season.
Gaudin (1-3) allowed five hits while throwing 102 pitches. Three relievers teamed to throw one-hit ball the rest of the way, with Heath Bell striking out two during a perfect ninth for his 11th save.
Emmanuel Burriss singled home Randy Winn with San Francisco's only run in the second, but the Padres tied it in the bottom half of the inning on Chris Burke's RBI double.
The go-ahead run came from Kevin Kouzmanoff, who homered on the first pitch of the fourth inning from Jonathan Sanchez (1-4). It was the third home run of the season for Kouzmanoff.