With the score tied 10-10, Stanford (6-2, 4-1 Pac-12) converted three third downs on a 13-play drive capped by Hewitt's 1-yard TD run with 8:04 left in the third period.
Josh Nunes threw for a touchdown, going 7-of-15 for 136 yards, and Ed Reynolds iced the victory with a 25-yard interception return for a score.
Stepfan Taylor contributed 58 yards on 21 carries as the Cardinal claimed a second straight victory.
The Cougars (2-6, 0-5) were led by Jeff Tuel, who amassed 401 yards with two touchdowns and an interception on 43-for-60 efficiency.
Megyn Kelly: Santa Claus and Jesus are both white men
Costly malfunction causes beer flood at Boston-area brewery