Cain (9-2), coming off a perfect game in his previous outing, struggled against the Angels, issuing four walks and allowing three runs over five innings. But he garnered his eighth win in eight starts with the help of the Giants' bullpen, which set down 15 straight Los Angeles batters.
Shane Loux, Sergio Romo and Jeremy Affeldt combined for three innings of hitless relief and Santiago Casilla nailed down his 19th save with a 1-2-3 ninth for San Francisco, which took the opener of a three-game road series.
Ryan Theriot went 3-for-5 with a pair of RBI singles and Brandon Crawford delivered a two-run triple for San Francisco.
Angels starter Jerome Williams (6-5) lasted 3 1/3 innings, allowing four runs on seven hits.
Williams was hospitalized with breathing problems after being taken out the game. The right-hander was to be kept overnight for observation, USA Today reported.
Mark Trumbo homered and Mike Trout stole three bases for the Angels.
Jordana Brewster on Paul Walker: 'He was an enormous presence in my life'
Gal Gadot cast as Wonder Woman for 'Batman vs. Superman'