The Ducks lost for the first time this season and almost certainly saw their hopes for a national title come to an end.
Oregon's setback left major college football with six unbeaten teams with Alabama and Florida State currently in the best position to meet for the national crown.
After averaging 55 points in their first eight games of the season, the Ducks were held scoreless for the opening three periods against Stanford.
Oregon then put on an amazing comeback that featured a blocked field goal return for a score as well as a recovered onside kick.
Having scored 20 consecutive points, however, Oregon's hopes ended when another attempt at an onside kick was recovered by Stanford with two minutes to play.
The result left both Oregon and Stanford with 8-1 records overall. They are tied at the top of the Pacific-12 North Division at 5-1.
Stanford took a 14-0 lead on touchdown runs of 2 yards by Tyler Gaffney and 11 yards by quarterback Kevin Hogan. Williamson then finished off drives with field goals of 19, 34, 26 and 30 yards -- the last of those coming with 11:40 to play and seemingly putting the game out of reach.
Marcus Mariota finally put Oregon on the board with a 23-yard scoring throw to Daryle Hawkins and the Ducks' hopes grew when Rodney Hardrick ran a blocked field goal try back 65 yards for a touchdown with 5:08 to go.
The ensuing onside kick bounced off two Stanford players before being recovered by the Ducks and that led to a 12-yard scoring pass from Mariota to Pharaoh Brown.
Gaffney ran for 157 yards on 45 carries to help control the clock while Hogan completed 7-of-13 for 103 yards without an interception.
Stanford outgained Oregon's normally potent offense 377 yards to 311.
In addition to Alabama and Florida State, the unbeaten teams remaining include Ohio State, Baylor, Fresno State and Northern Illinois. Baylor kept its perfect season going earlier Thursday by overwhelming Oklahoma.
'Happy' fan videos make Pharrell cry [VIDEO]
Pregnant Mila Kunis wins 'Best Villain' at MTV Movie Awards