ESPN viewers around the country might have been drawn to watch Saturday night's Stanford-Oregon State game mainly by the expected treat of seeing the Beavers' dynamic passing offense.

Instead, the Stanford defense defused the nation's most explosive aerial game with an inspired performance and probably put many of the viewers to sleep.

The No. 8 Cardinal kept Sean Mannion and Brandin Cooks, the top statistical passer and receiver in the country, under wraps most of the night, and had eight sacks.

Meanwhile, Stanford's Tyler Gaffney had 145 yards rushing and three touchdowns as the Cardinal won 20-12 after a last-minute red-zone stand and spoiled OSU's homecoming at Reser Stadium.

The win lifted Stanford to 7-1 overall and 5-1 in the Pac-12, while Oregon State (6-2) sustained its first Pac-12 loss after four wins.

The win sets up a showdown at Stanford Stadium on Nov. 7 with No. 2 Oregon (8-0, 5-0). The Ducks will be eager to avenge last year's 17-14 overtime loss to the Cardinal, which knocked Oregon out of a shot at the BCS championship game.

Oregon State gambled on 4th down four times in Stanford territory. All four times it came up empty, thanks to a clinging pass defense and a strong pass rush.

Nursing a 7-3 lead, the Cardinal caught a break when Oregon State freshman Victor Bolden fumbled the second-half kickoff. Two plays later Tyler Gaffney scored his second touchdown of the game on a bulldozing 9-yard run. Conrad Ukropina, filling in for injured kicker Jordan Williamson, missed the PAT, so Stanford led 13-3.

Mannion's 9-yard touchdown pass to Cooks cut the lead to 13-9 late in the third quarter. It was Cooks' 13th TD catch of the season, breaking an OSU record. Trevor Romaine's PAT try was blocked.

But Stanford pushed the lead to 20-9 early in the fourth quarter on Gaffney's third touchdown, a 32-yard run.

A fumble by Gaffney with a little over four minutes left gave the Beavers the ball on the Stanford 20. Trevor Romaine's 39-yard field goal cut the lead to 20-12 with three minutes left.

Stanford moved deep into Beavers territory on its second series of the game, as Kelsey Young ran 15 yards on a fly sweep after a handoff by Tyler Gaffney from the wildcat formation and Ty Montgomery ran for nine yards and caught a 10-yard pass. But Dallas Lloyd, temporarily replacing Kevin Hogan, fumbled in his indecision after a fake handoff to Ricky Seale, and defensive end Scott Crichton returned it 36 yards to the Stanford 42.

Sacks by Ben Gardner and Trent Murphy, however, stymied the Beavers, who despite the excellent field position were forced to punt.

Cooks uncorked a 41-yard punt return down the right sideline, again giving the Beavers good field position at the Stanford 39. Trevor Romaine bombed a 50-yard field goal to give Oregon State a 3-0 lead early in the second quarter.

The Cardinal's swarming defense was at its best on that series when Cooks grabbed a bubble screen pass. Backtracking to find running room, he wound up losing seven yards when he was corralled by Murphy and Josh Mauro.

Oregon State forced a three-and-out, and Mannion passed the Beavers to the Stanford 18, where the Cardinal's defense stiffened.

Stanford finally got on the scoreboard with just seven seconds left in the half on a fine second-effort run by Gaffney from four yards out. The run gave Gaffney 66 yards rushing in the first half.