Tyler Gaffney (25) carries the ball in the first quarter, defended by Derrick Malone Jr. (22) The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013. Stanford defeated the Ducks 26-20.

Photo: Carlos Avila Gonzalez, The Chronicle

Tyler Gaffney (25) carries the ball in the first quarter, defended...

Image 5 of 13

Stanford head coach David Shaw gestures to an official in the fourth quarter. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013. Stanford defeated the Ducks 26-20.

Photo: Carlos Avila Gonzalez, The Chronicle

Stanford head coach David Shaw gestures to an official in the...

Image 6 of 13

Tyler Gaffney, center, runs into the end zone in the first quarter for Stanford's first touchdown. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013.

Photo: Carlos Avila Gonzalez, The Chronicle

Tyler Gaffney, center, runs into the end zone in the first quarter...

Image 7 of 13

Stanford fans cheer the team's defeat of the Oregon Ducks on Thursday. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013. Stanford defeated the Ducks 26-20.

Photo: Carlos Avila Gonzalez, The Chronicle

Stanford fans cheer the team's defeat of the Oregon Ducks on...

Image 8 of 13

Antonio Lucero of Grass Valley, left, smiles as his friend, Ryan Hummer of Oakland, right, looks at the field as the Ducks fell to the Cardinal on Thursday. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013. Stanford defeated the Ducks 26-20.

Photo: Carlos Avila Gonzalez, The Chronicle

Antonio Lucero of Grass Valley, left, smiles as his friend, Ryan...

Image 9 of 13

Oregon head coach Mark Helfrich gestures to an official in the fourth quarter. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013. Stanford defeated the Ducks 26-20.

Photo: Carlos Avila Gonzalez, The Chronicle

Oregon head coach Mark Helfrich gestures to an official in the...

Image 10 of 13

Kevin Hogan (8) scrambles in the fourth quarter. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013. Stanford defeated the Ducks 26-20.

Photo: Carlos Avila Gonzalez, The Chronicle

Kevin Hogan (8) scrambles in the fourth quarter. The Stanford...

Image 11 of 13

Marcus Mariota fumbles the ball near the end zone but managed to recover it in the fourth quarter. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013. Stanford defeated the Ducks 26-20.

Photo: Carlos Avila Gonzalez, The Chronicle

Marcus Mariota fumbles the ball near the end zone but managed to...

Image 12 of 13

Henry Anderson, right, and Trent Murphy, left, celebrate sacking Marcus Mariota in the first quarter. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013.

Photo: Carlos Avila Gonzalez, The Chronicle

Henry Anderson, right, and Trent Murphy, left, celebrate sacking...

Image 13 of 13

Tyler Gaffney runs for the Cardinal in the first quarter. The Stanford Cardinal played the Oregon Ducks at Stanford Stadium in Stanford, Calif., on Thursday, November 7, 2013.

A year after an astonishing upset of then-No. 1 Oregon, the Cardinal played their ball-control, stout-defense game to perfection Thursday night and again shocked the Ducks, this time ranked No. 2 in the country.

Tailback Tyler Gaffney was a nearly unstoppable force, rushing for 157 yards on a school-record 45 carries, but the Ducks made the game a white-knuckler at the end.

Gaffney and quarterback Kevin Hogan ran for touchdowns, Jordan Williamson kicked four field goals, and the Stanford defense rose to the occasion as the No. 6 Cardinal won 26-20 in a game that shouldn't have been that close.

"You control the line of scrimmage, you have a chance to win," Stanford head coach David Shaw said. He called the game a "more complete performance" than last year's 17-14 overtime win in Eugene.

Stanford (8-1 overall) took over first place in the Pac-12 North Division with a 6-1 record by handing the Ducks their first loss under rookie head coach Mark Helfrich.

Before a packed house of 51,545 at Stanford Stadium, the Cardinal also moved themselves firmly into contention for the national championship - and those words must lift eyebrows around the nation because the Stanford program was all but comatose just seven years ago.

Oregon entered the game as the second-most explosive offense in the country, with an amazing 632 yards of total offense and 56 points per game. Only Baylor's 718/64 were better.

Stanford's defense made the Ducks look ordinary. For more than 49 minutes, the Cardinal pitched a shutout.

Marcus Mariota, Oregon's Heisman Trophy candidate, was flustered into a very rocky evening, completing 20 of 34 passes for 250 yards, way below his typical numbers. He couldn't get Oregon (8-1, 5-1) into the end zone until he hit Daryle Hawkins for a 23-yard touchdown with 10:11 left.

Until that play, Stanford had held Oregon scoreless in 12 straight possessions going back to last year's game.

The Ducks cut the lead to 26-13 when Rodney Hardrick returned a blocked field-goal try for a touchdown with a little more than five minutes left. The Ducks failed on a two-point conversion try, but they recovered an onside kick. And on a fourth-down play, Mariota hit tight end Pharaoh Brown with a 12-yard touchdown pass to cut the lead to 26-20 with 2:12 left.

What looked like a Stanford romp had become a thriller. Shaw likened the Ducks' run to a waterfall. "It didn't seem like it was ever going to end," he said, "but our guys didn't panic."

Backup wide receiver Jeff Trojan recovered his second onside kick of the final quarter, and Stanford ran out the clock.

"We knew they were a dangerous team," said linebacker Shayne Skov, who had a team-high nine tackles, two forced fumbles and a recovery. "We weren't going to let it slip away."

Stanford didn't commit a turnover, recovered two Oregon fumbles, nearly eliminated the Ducks' big gainers and had a whopping advantage (42:34-17:26) in time of possession. The Cardinal was assessed just two penalties for 10 yards, the Ducks 10 for 81.

Mariota was under heavy pressure all night by coordinator Derek Mason's rugged defense and couldn't find open receivers because of the clinging coverage. Oregon was held to 62 yards rushing.

Meanwhile, the Stanford offensive line had its way, repeatedly opening holes for Gaffney even when everybody in the stadium knew he was going to get the ball.

Hogan didn't have to pass much (7-for-13, 103 yards), but he frustrated the Ducks several times with runs for first downs.

A 57-yard return by Stanford's Ty Montgomery of the second-half kickoff set up a Williamson field goal that opened a 20-0 lead.

A field goal following Mariota's fumble made it 23-0, and a personal-foul penalty against Ducks safety Brian Jackson was a key play in the drive that led to another field goal early in the fourth quarter.

In the first quarter, Gaffney's 2-yard touchdown run finished a drive keyed by Hogan's 47-yard pass to Michael Rector.

Pass interference against Oregon cornerback Ifo Ekpre-Olomu helped Stanford open a 14-0 cushion in the second quarter. Hogan soon bolted 11 yards for a touchdown.

The Ducks finally got rolling, but Skov came to the rescue. De'Anthony Thomas was ruled to have caught a pass that would have put Oregon on the Stanford 2; the officials said he was down before the ball was knocked from his grasp. Replays found that Skov had stripped him of the ball and made the recovery at the 2 with 8:26 left in the second quarter.

Oregon didn't hold the ball again for the rest of the half.

Stuffed Ducks

Oregon's offense entered the game as one of the most prolific in the nation. A look at the Ducks' per-game averages compared with Thursday's stats: