Kevin Hogan threw for three touchdowns, including the game-winning pass to Zach Ertz late in the fourth quarter, as No. 16 Stanford edged 13th-ranked Oregon State, 27-23, at Stanford Stadium.
Hogan completed 22-of-29 passes for 254 yards with two interceptions for the Cardinal (8-2, 6-2 Pac-12), who have won four straight.
"I'm happy that we got the win. Some incompletions here and there, the interceptions, obviously, you want to protect the ball at all time. In the end, we got our goal, so I'm happy about that," Hogan said.
Ertz finished with 75 yards on nine receptions, while Stepfan Taylor added 114 yards and a touchdown on 19 carries in the win.
Taylor also had 47 yards and a touchdown on two receptions.
Cody Vaz threw for 226 yards and a touchdown on 23-of-38 efficiency for Oregon State (7-2, 5-2), which has dropped two of three.
Markus Wheaton had seven receptions for 91 yards and a score, and Storm Woods carried the ball 15 times for 94 yards in defeat.
"They were real physical but I think our O-line did a good job and we were able to gash them a couple time and I think we were pretty productive on the run today," Woods said.
Oregon State trailed 14-10 at the half, but opened the third quarter with a 10-play, 75-yard scoring drive Brandin Cooks kept alive with a 15-yard reception on a 3rd-and-8. Wheaton grabbed a pass over the middle and raced 22 yards into the end zone to give the Beavers their first lead of the game.
Ryan Murphy then intercepted a tipped Hogan pass on Stanford's ensuing drive and returned it to the Cardinal 27, setting up Trevor Romaine's 42-yard field goal for a 20-14 advantage.
The Beavers regained the ball at the Cardinal 49-yard line following a Stanford three-and-out, and capitalized on the favorable field position with a 44-yard kick by Romaine.
Stanford was finally able to stop the bleeding on its next touch as Hogan converted a pair of third downs before hitting Taylor with a short pass to the left side. He broke a couple of tackles en route to a 40-yard touchdown on the final play of the third quarter, bringing the Cardinal within 23-21.
The Cardinal started their next drive at their own 20 with a chance to retake the lead after Stanford's defense made its first stop of the second half, but Hogan was intercepted by Rashaad Reynolds at the Beavers' 30 on a deep pass attempt down the left sideline.
Two plays later, however, Vaz had the ball slip out of his hands while he was scrambling away from pressure and Stanford recovered at the Oregon State 29.
Taylor then converted a 3rd-and-5 with a 6-yard rush before Stanford was able to capitalize on the turnover with the game-deciding 14-yard touchdown grab by Ertz.
Hogan was stopped short of the goal line on a sneak during a two-point conversion attempt to keep Stanford's lead at 27-23 with 5:07 left in the game.
"It started off as a run, Kevin changed the play and made a great throw to Zach in the back of the end zone. Phenomenal throw," Stanford coach David Shaw said.
The Beavers later took over on offense at their own 16 with 3:46 remaining following a punt by each team, but Vaz was shaken up during a sack and backup quarterback Sean Mannion failed to convert a 4th-and-16, allowing Stanford to run out the remainder of the clock.
Oregon State caught an early break when Michael Doctor recovered an Ertz fumble at the Stanford 46 on the third offensive play of the game, but the Beavers would manage just three yards and were forced to punt.
Hogan then hit three different receivers for double-digit gains, including an 18-yard strike to Ertz on a 3rd-and-3, before Taylor capped the ensuing 13- play march with a 1-yard rumble across the goal line with 5:41 left in the first quarter.
Stanford regained the ball at its own 20 following another Oregon State punt, and Ryan Hewitt's 24-yard reception highlighted a 10-play drive that saw just one third down and was finished with Hewitt's 12-yard touchdown grab.
The Beavers got on the board on their ensuing possession as Woods reeled of a pair of 12-yard runs before Terron Ward capped the 10-play, 81-yard trek with a 7-yard touchdown run less than five minutes into the second quarter.
Oregon State marched all the way down to the Stanford 3-yard line following a Cardinal three-and-out, keeping the drive alive by converting a 4th-and-1 at the Stanford 12 with a 1-yard push up the middle by Vaz. The Beavers, though, could not find the end zone and had to settle for Romaine's 19-yard field goal with 2:21 left in the second quarter.
The Cardinal quickly moved into Oregon State territory looking to increase its lead before the break, but Sean Martin recovered a Taylor fumble at the Oregon State 26.
Jordan Williamson then missed a 51-yard field goal as time expired to keep it a 14-10 game at the half.
Taylor now has 1,061 rushing yards on the season, making him the first Stanford running back all-time to record three straight 1,000-yard rushing seasons ... The Cardinal have now won eight straight home games ... Stanford held a 417-312 advantage in total yards ... Oregon State went 3-for-13 on third-down conversions ... Stanford was 7-for-12 on third downs.