Cain (1-1) struggled with his control but managed to hold the Cardinals scoreless, allowing five hits and a walk while striking out four as the Giants rebounded from a 3-games-to-1 deficit to take the NL Championship series 4-3.
Cain added an RBI single while Hunter Pence's two-run double highlighted a five-run second inning that carried the Giants to the 22nd NL pennant in their 129-year history.
San Francisco now goes on to face the AL champion Detroit Tigers in the World Series, which begins Wednesday in AT&T Park.
Marco Scutaro went 3-for-4 with a run scored while Brandon Belt homered and Angel Pagan, Pablo Sandoval and Brandon Crawford each added RBI as the Giants triumphed for the sixth time in an elimination game in the 2012 post-season.
Kyle Lohse (1-1) was roughed up for five runs on six hits over two full innings for the defending world champion Cardinals.
Millions of Getty images now available for free via embed tool
NBC reportedly holds celebs hostage to Jimmy Fallon's show