Heisman Trophy contender Marcus Mariota was inaccurate and under pressure much of the night, but he threw two fourth-quarter touchdown passes, sandwiched around a blocked field goal return for a score by Rodney Hardrick, to pull the Ducks (8-1, 5-1) to 26-20 with 2:12 left.
Oregon couldn't recover a second onside kick and Stanford ran out the clock.
And the biggest winner of all? No. 3 Florida State. The Seminoles don't have to worry about the Ducks nudging them out of second place in the BCS standings.
FSU was in danger of slipping to third in the BCS if Oregon could have registered a big road victory against a quality opponent. Now, the Seminoles face a manageable remaining schedule with a good chance to win their way to the BCS championship game at the Rose Bowl in January.
Unbeaten Baylor and Ohio State have to be happy, too, with one less hurdle to clear.
As for Stanford, it gets first place in the Pac-12 North and the inside track to another league title game. And maybe if things get really weird, the Cardinal can get back in the title hunt.
Stanford won a three-point game in overtime at Oregon last year to deny the Ducks a chance to play for the national title, but it didn't look as if there would be much drama in the return bout on the Farm. Stanford led 17-0 at halftime and added three more field goals by Josh Williamson in the second half.
Oregon looked like dead Ducks, down 26-0 early in the fourth with Stanford hammering away behind Gaffney, who set a school record with 45 carries. Even after Oregon finally broke the seal with a 23-yard touchdown pass from Mariota to Daryle Hawkins, the Cardinal went on another time consuming drive and attempted a long field goal that would have sealed it.
Instead, the Ducks blocked it, Hardrick scooped and scored from 65 yards out with 5:08 left and suddenly it was interesting.
Only 5 seconds later it got even more interesting when the Ducks recovered an onside kick. They quickly moved inside the Stanford 5, but got pushed back to a fourth-and-goal from the 12. Mariota threw a touchdown pass to Pharoah Brown with 2:12 remaining, but the time it took the Ducks to get in while burning a timeout was key.
Stanford grabbed the next onside kick and Oregon was powerless to stop the clock.
Stanford put Oregon in a 14-0 hole, the Ducks' largest deficit of the season, with a power football clinic that started when the Cardinal came up with a fourth-and-goal stop from the 4 in the first quarter.
Stanford followed with a punishing 96-yard drive that included one long strike from Hogan to Michael Rector. Gaffney's 2-yard plunge made it 7-0.
With a little help from a pass interference call that wiped out an Oregon interception, Stanford made it 14-0 on Hogan's option keeper from 11 yards out with 11:26 left in the second quarter.
And just when it looked as though Oregon was about to get back in it, Stanford linebacker Shayne Skov ripped the ball away from De'Anthony Thomas at the Stanford 2.