Anderson had a chance to intercept a pass early in the second quarter but he could not hold on, and it resulted in a Michigan State reception.
Stanford, which lost 24-20 to the Spartans in the 100th Rose Bowl on Wednesday, went into hibernation for much of the second quarter, gaining 22 offensive yards and giving up 157 yards, including two long scoring drives.
Anderson, who also recorded a tackle for a loss in the quarter, made sure he hung on the next time the ball came his way.
His heads-up play turned into a 40-yard interception return for a score kept the Cardinal in front at 17-7. It was his first career interception and marked Stanford's 37th forced turnover in its past 38 games.
After the Spartans closed to within 10-7, helped in large part by a pass interference call on Wayne Lyons in the end zone on a third-and-goal play, Stanford made it as far as midfield before punting the ball away. Half of the six plays either lost yardage or did not gain yardage.
The Cardinal woes continued after holding Michigan State on its next possession. It started on the Spartans punt when Patrick Skov was nailed with a personal foul and Stanford was forced start on its own eight.
A false start cost Stanford another four yards and Tyler Gaffney lost two yards on an ill-advised Wildcat play, in which he took the direct snap. Gaffney made up three yards on the next play but an incomplete pass forced Ben Rhyne to punt.
Rhyne entered the game averaging 3.6 punts a contest. He punted five times against Michigan State for an average of 49.8.
That's when Anderson stepped in and saved the day, at least for the time being. He was right in the middle of what was supposed to be a screen pass.
Usua Amanam pressured MSU quarterback Connor Cook into rushing his throw and Anderson gladly accepted the ball and raced 40 yards for the score.
"I heard the crowd yelling and saws Kevin with the ball," said Amanam, the Defensive MVP of last year's Rose Bowl. "I was glad to see Kevin make the play, after all the hard work he has put in."
The Spartans only needed 1:39 to respond with another touchdown, to close within 17-14 by halftime.
"They took advantage of their opportunities," Stanford free safety Ed Reynolds said. "Everything we prepared for is exactly what they did."
Despite losing much of its defense, quarterback Kevin Hogan, who lost to a ranked opponent for the first time in 11 starts, thinks Stanford will continue to be in future Pac-12 title hunts.
"We got back to the Rose Bowl this year and we can't hang our heads," he said. "We'll be back. It's tough to go out with a loss but these guys have been doing such a great job for four years."
NOTES: Stanford set a single-season rushing record with 2,904 yards . . . The Cardinal defense has recorded at least one sack in 33 of its past 34 games . . . Stanford allowed fewer than 30 points for the 23rd consecutive game . . . Shayne Skov recorded nine tackles and finished with 109, the most since Bo McNally had 114 in 2007 . . . Ty Montgomery, who left the game with an injury, finished with 1,091 return yards, the second Stanford player to reach the 1,000-yard milestone. His 2,208 all-purpose yards this season rank him No. 3 in school history . . . Stanford is 11-13-1 in bowl games, 6-7-1 in the Rose Bowl . . . Stanford became the only team ever to play in the first Rose Bowl (1902) and the 100th, unfortunately losing both . . . The Cardinal fell to 15-43-3 all-time against top-five opponents . . . Gaffney finished his final season with 330 rushing attempts for 1,709 yards and 22 touchdowns. Those totals rank him No. 2, 2 and 3 in school history, respectively . . . Junior wide receiver Devon Cajuste finished the season by averaging 22.9 yards per catch, setting a single-season school record . . . With Stanford's loss, the Pac-12 finished 6-3 in bowl games this season. It was the first time the conference has won that many bowls after going 5-0 in 2008 and 5-1 in 1997.