Cain struck out 11 in his first complete game of the season and also hit an RBI double that helped the Giants beat the Washington Nationals 3-1 on Wednesday for their sixth win in eight games.
"He did it all," manager Bruce Bochy said. "It was quite a job for Matty. He pitched very efficiently, had all his pitches going. ... It was a great all-around game for him."
Rookie Brandon Crawford hit a tiebreaking RBI triple in the seventh inning and later scored an insurance run to help first-place San Francisco win its their third straight series.
The Giants have played just 11 games this season that have been decided by more than three runs as they kept to the strong-pitching, low-scoring formula that helped them win the World Series last year.
Yunesky Maya delivered the best performance of his career but remained winless in eight career starts as the Nationals could only muster an RBI double by Rick Ankiel in the seventh inning against Cain (5-4).
Cain and Maya were strong early, with the game remaining scoreless until the bottom of the sixth inning. That's when the Giants came through with back-to-back, one-out doubles by Eli Whiteside and Cain. The hit was just the third in 27 at-bats this season for Cain and his first RBI in exactly one year.
"The double definitely felt good to get us going a little bit," Cain said. "Their guy was throwing the ball well, keeping us off balance."
The Nationals answered in the bottom half when Mike Morse hit a leadoff single and later scored on Ankiel's two-out double. That's just the fifth run the Nats have scored for Maya in his eight big-league starts.
The Giants ended up taking the lead back in the bottom half of the seventh when Crawford hit a two-out, RBI triple off Sean Burnett (1-3) and then scored on Whiteside's single.
Burnett also allowed a two-run single to Aubrey Huff on Monday to contribute to a loss and blew a lead last week in Philadelphia as his struggles have continued.
"When I needed to make a pitch it wasn't there," said Burnett, who has a 5.96 ERA. "I came in and gave it away. I'm costing the team ballgames every time I go out there. I'm not getting the job done, bottom line."
That two-run lead proved to be more than enough for Cain, who improved to 16-0 over the past two years when getting at least three runs of support. He allowed five hits and one walk in his 13th career complete game, needing just 110 pitches.
"He had four pitches going today," Whiteside said. "He was able to get his curveball over for a strike. That was a big pitch for him to steal a strike early and go from there. He was great."
Cain was dominating from the start with the only hit he allowed in the first five innings coming on Danny Espinosa's bunt with two outs in the second. The Nationals got their first clean hit with two outs in the sixth when Ian Desmond lined a single to left-center.
But Washington was unable to generate any threats against Cain, who struck out the side in order in the fourth inning against the middle of the Nationals lineup.
"I felt good," Cain said. "We were just ahead in the count a lot. Eli was calling a lot of good pitches. We were on the same page early."
The Giants didn't fare much better early against Maya, despite getting leadoff hits in the second and third innings. Aubrey Huff was doubled off first to end the second when he ran on Aaron Rowand's blooper that was caught by right fielder Laynce Nix. Brandon Crawford was then caught stealing for the second out in the third inning by Wilson Ramos, who has thrown out 11 of 23 attempted basestealers.
Maya allowed one run and four hits in six innings and remained winless in his career as the Nationals were unable to get any offense going against Cain.
"I threw a lot more strikes and attacked the zone," Maya said through an interpreter. "I felt like I wasn't doing that before. I worked a little bit on my mechanics and felt a lot better. I pitched with confidence."
The Nationals won the season-series with the World Series champion Giants 4-3. ... Cain has seven double-digit strikeout games in his career. ... Washington stole two bases against Whiteside. Giants catchers have thrown out just two of the past 22 attempted basestealers. ... Giants 3B Pablo Sandoval (right wrist) INF Mike Fontenot (right groin) will play for Triple-A Fresno at Salt Lake this weekend. Sandoval said he hopes to be back with the Giants next week in Arizona.