Stanford stuffed UCLA three-and-out and Terrell returned the punt 18 yards to the Bruins 43. That set up Williamson's tiebreaking field goal.
One last UCLA drive nearly sent the game to overtime.
Tight end Joseph Fauria caught a pass over the middle on fourth-and-7 and lateraled the ball to Jordon James to finish a 17-yard completion. That helped set up Fairbairn's field goal with 34 seconds left, and the kick never looked on target.
"There's a lot of tears and a lot of disappointment but I think they should be proud of what we accomplished," first-year UCLA coach Jim Mora said.
Stanford has won five straight against the Bruins, who were going for their first conference championship since 1998.
The crowd was the smallest at 50,000-seat Stanford Stadium since the Cardinal drew 30,626 against Sacramento State on Sept. 4, 2010.