Cain (7-2) allowed seven hits and struck out nine, and ran his winning streak to six straight starts for the Giants, who won for the ninth time in 11 games.
The Giants went up 4-0 in the third on a solo home run by Buster Posey, who had driven in a run in the first with a single. The Padres scored three times in the bottom of the third, aided by two San Francisco errors.
Angel Pagan hit a two-run shot in the seventh and Gregor Blanco had a solo home run in the eighth for the Giants.
Jason Marquis (0-1), making his first start for the Padres, went six innings, giving up four runs -- two earned -- on nine hits and striking out six.
The Padres, who left the bases loaded in the eighth and ninth innings, have lost three of their last four and eight of their last 210.