The victory gave the Giants a sweep in the three-game series and gave Cain his first win against eight losses in 15 starts against the Dodgers. He scattered four hits and a walk, and struck out seven to improve to 9-8 this season.
Brian Wilson shut the door for his 31 save.
The Giants have now won 21 of their last 27 games.
Clayton Kershaw (10-6), in his first start since serving a five-game suspension for hitting Giants outfielder Aaron Rowand, took the loss. He gave up two runs on six hits and four walks in seven innings. He struck out six for the Dodgers, who have lost five straight.
Renteria provided the game's only runs in the sixth inning, driving in Pat Burrell, who had doubled with one out, and Aaron Rowand, who was intentionally walked with two outs, with a line drive into the left-center field gap.