The right-hander, who will be the Giants' No. 2 starter behind left-hander Madison Bumgarner during the regular season, threw 59 pitches and struck out seven.
Right-hander Jeff Samardzija, the Cubs' opening-day starter, also had an effective outing. He gave up two runs in four innings and struck out five.
Pablo Sandoval's two-run single in the fourth gave the Giants an early lead, but the Cubs scored a run in the sixth and two in the seventh. The decisive run scored on two infield errors as part of the same play.
Cubs: Samardzija set career marks last year with 33 starts, 213 2-3 innings pitched and 214 strikeouts in his second full season in the rotation. He was the first Cubs pitcher to reach both 200 strikeouts and 200 innings since Ryan Dempster in 2010. He was 8-13 with two complete games, one shutout and a 4.34 ERA.
Giants: Cain is feeling much better about himself than he last year, when he was 8-10 in 30 starts.
''Last year, I gave up a lot of two-strike hits. I didn't finish the hitter off for some reason,'' Cain said. ''Today, we were able to able to finish off the hitters. We threw better pitches when we were ahead in the count, which is always nice.''
The entire starting staff appears to be more focused this spring with an eye on the regular season, which begins March 31 on the road against the Arizona Diamondbacks.
''I wouldn't say we have really talked about it much, but we know what needs to be done,'' Cain said.
Giants: Left fielder Michael Morse returned to the lineup after missing three games with a strained calf and had a hit. ... Right fielder Hunter Pence also had a double after dealing with a sore left elbow.
FORMER GIANTS SHINE
Left-hander Jonathan Sanchez, who pitched a no-hitter for San Francisco against the San Diego Padres in July of 2009, earned the save on Monday for the Cubs against his former team, his second save of the spring. The man who caught that no-hitter, Eli Whiteside, also is with the Cubs now and started Monday's game.
Sandoval appears to be locked in at the plate for the Giants. He had two more hits, raising his spring average to .381.