Cain faced elbow and hamstring troubles in the latter years of his career. On September 27, Cain announced that he would retire at the end of the season, making him just the fourth player in the San Francisco Era to spend his entire career with the Giants (minimum of 10 seasons), joining Jim Davenport (-), Scott Garrelts (-), and Robby Thompson (-). On September 30, 2017, Cain pitched five shutout innings in his last career game. Cain finished his Giants career second all-time among Giants pitchers in the San Francisco era with 331 starts (behind Juan Marichal), third in innings pitched with 2,085 (behind Marichal and Gaylord Perry), and third in strikeouts with 1,694 (behind Marichal and Tim Lincecum).