SEATTLE (AP) Myles Gaskin returned after missing two games due to a shoulder injury to rush for 148 yards and one touchdown, and Washington built a big early lead before needing Taylor Rapp's interception on the final play to beat Stanford 27-23 on Saturday night.

The matchup was essentially an elimination game in the Pac-12 North Division race and the Huskies got their senior star ball carrier back on the field just in time. Gaskin sat out a win over Colorado and loss to California, and his absence only highlighted his importance to Washington's offense.

''He's the best at hiding behind his guys, letting things develop and getting to the right spot,'' Washington coach Chris Petersen said.

The Huskies (7-3, 5-2 Pac-12) built a 21-0 lead thanks to a 2-yard touchdown run by quarterback Jake Browning, an 11-yard TD pass from Browning to Drew Sample and Gaskin's 6-yard run early in the second quarter. But the Huskies offense became conservative and was unable to find the end zone the rest of the way, making for a nervy second half after Stanford's K.J. Costello got hot.

''When things are tough and things are dark and it's us against the world, we are at our absolute best. I love that about our guys,'' Stanford coach David Shaw said. ''The problem is we create the situation that puts us there. We've got to find a way to stop screwing it up to get ourselves to the point where we have to play our best just to come back and be in the game.''

Costello threw a 14-yard touchdown to Kaden Smith and Bryce Love ran for a 5-yard TD late in the third quarter to pull Stanford (5-4, 3-3) within 24-14. Collin Riccitelli hit a 21-yard field goal with 9 minutes remaining after Washington's defense held inside the 10 to pull the Cardinal within 24-17.

Washington answered with one more drive and Peyton Henry hit a 38-yard field goal with 5:09 left and gave the Huskies a 10-point lead, but Costello made the final minutes uncomfortable hitting Trenton Irwin for a 33-yard touchdown with 3:24 left. Riccitelli missed the extra point and the Huskies lead was 27-23.

Washington was only able to run 79 seconds off the clock before punting and Stanford took possession at its 15 with 2:05 left. Costello hit five passes to get to the Washington 34 with 10 seconds left. He missed an end zone throw for Irwin and on the last play Costello was intercepted by Rapp at the goal line.

Costello was 29 of 43 for 347 yards, two touchdowns and three interceptions. Love rushed 18 times for 71 yards.

Browning finished 16 of 27 for 194 yards and one score.

Washington's first quarter and most of the first half was nearly flawless. The Huskies scored touchdowns on their first three drives. They picked off Costello twice, including a diving interception by 320-pound defensive tackle Greg Gaines off a pass deflected by Ben Burr-Kirven. Stanford failed to get a first down in the first quarter and had just 96 yards of offense until the final drive of the half.

INJURIES

Stanford played the final 2 1/2 quarters without leading receiver J.J. Arcega-Whiteside after he left midway through the second quarter with a right ankle/foot injury. Arcega-Whiteside was held without a catch until grabbing a pass from Costello with 5:24 left in the first half. Arcega-Whiteside appeared to be injured while being tackled and left the field with help from trainers.

THE TAKEAWAY

Stanford: The Cardinal remained winless this season when not forcing a turnover. ... Stanford has lost four regular season games in consecutive seasons for the first time since the 2008-09 seasons.

Washington: The Huskies still have a path to the Rose Bowl in their control. After a bye next week the Huskies will host Oregon State. A win against the Beavers would give Washington a chance to win the Pac-12 North by beating Washington State in the Apple Cup.

UP NEXT

Stanford: The Cardinal return home to host Oregon State.

Washington: The Huskies get a week off before hosting Oregon State on Nov. 17.

Copyright 2018 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.