LOS ANGELES -- Andre Heidari kicked a 47-yard field goal with 19 seconds to play, and Southern California's stalwart defense repeatedly came up big in a 20-17 victory over No. 5 Stanford on Saturday night.
Cody Kessler passed for 288 yards for the revitalized Trojans (8-3, 5-2 Pac-12), who earned their fifth win in six games under interim coach Ed Orgeron.
USC's remarkable defensive performance included two fourth-quarter interceptions against the powerful Cardinal (8-2, 6-2), who followed up last week's win over Oregon by getting knocked out of the national title chase and maybe the Rose Bowl race as well.
After the inconsistent Heidari's field goal and Stanford's final play, USC fans stormed the Coliseum field, where Stanford had won in its last three trips.
Heidari nearly lost his job twice this season, and he missed an extra point in the first quarter. But the junior coolly nailed the tiebreaking field goal -- and then got an unsportsmanlike conduct penalty for running the length of the field to celebrate it.
Soma Vainuku caught an early TD pass and Javorius Allen rushed for a score for USC, which didn't score in the second half until Heidari's kick. Nelson Agholor had eight catches for 104 yards, while Marqise Lee had six catches for 83 yards -- and both receivers made big plays on USC's final drive.
Tyler Gaffney rushed for 158 yards and two touchdowns for Stanford. Kevin Hogan went 14 of 25 for 127 yards, but the Cardinal couldn't regain the lead after trailing at half, despite repeatedly getting close.
After trailing 17-10 at halftime, Stanford calmly tied it with Gaffney's 18-yard TD run on the first drive of the third quarter. USC's offense struggled throughout the second half, but the Trojans' thin defense kept it close despite using just two substitutes for most of the night.
Dion Bailey intercepted Hogan's third-down pass at the USC 6 with about 10½ minutes to play, killing what seemed certain to be Stanford's go-ahead drive. Su'a Cravens then intercepted a tipped pass at the USC 44 with 3 minutes to play, giving another chance to the Trojans' offense.
After Lee caught a 13-yard slant pass over midfield on fourth-and-2, the Trojans reached the Stanford 21 before two straight yardage-losing plays pushed them back to the 30 -- and Heidari still nailed his kick.
Under the lights at the sold-out Coliseum, Stanford betrayed a few nerves early. The Cardinal burned two timeouts and committed an illegal-snap penalty on the game's first drive, and Ty Montgomery dropped two passes in the opening minutes.
USC's opening drive was smooth, with Lee making a tiptoe sideline catch before Vainuku came out of the backfield for a play-action 1-yard TD catch just 6:13 in.
Gaffney scored on a 35-yard run moments later when he popped out the back of a scrimmage pile and sprinted past the slumbering USC defense, but the Trojans answered with another long drive capped by Allen's 1-yard TD run and a 2-point conversion catch by Lee.
Kessler was outstanding in the pocket and on the run, completing 10 straight early passes before Heidari's field goal put the Trojans up by 10 points early in the second quarter. Stanford added a field goal with 17 seconds left the first half.
After Gaffney capped a 92-yard drive with his TD run up the middle, Stanford forced a fumble by Kessler at the USC 19, but the Cardinal's field goal attempt was blocked.
Stanford is USC's oldest rival in a series dating back to 1905. The Cardinal had never won four straight in the series before the last four meetings.
Former Stanford lineman Jonathan Martin watched the game from the sideline in a backward Cardinal cap.