Cain (12-2) gave up one run and struck out five as he moved to 37-6 all-time when the Giants score three or more runs for him.
Jeremy Affeldt pitched a perfect eighth - his 27th straight scoreless inning
- and Brian Wilson got Troy Tulowitzki to hit into a game-ending double play in the ninth for his 25th save.
Although Cain struggled with his command at times, issuing four walks, he didn't allow his first hit until the fifth when Ian Stewart lined a two-out hopper through the right side of the infield.
Cain joins Colorado's Jason Marquis as the only 12-game winners this season. Marquis was scheduled to pitch Friday, but was bumped due to a bothersome blister on his right middle finger.
Jason Hammel (5-5) filled in, giving up three runs and seven hits in six innings.
The Rockies had a two-out rally going in the sixth after Ryan Spilborghs doubled and Todd Helton walked. Garrett Atkins laced an RBI double to left, but Cain struck out Brad Hawpe to limit the damage to one run.
Lewis finds hitting at Coors Field to his liking, increasing his career batting average to .365 with a 3-for-3 night. He scored two of San Francisco's runs.
The left-handed hitting Lewis singled in the first, doubled in the fourth and tripled in the sixth. In his final at-bat in the eighth, he was walked on five pitches by southpaw Franklin Morales.
Lewis hit for the cycle on May 13, 2007, at Coors Field.