MANHATTAN, Kan. (AP) West Virginia coach Neal Brown was staring down the prospects of a six-game losing streak amid his first season in Morgantown, a streak of futility unmatched by the Mountaineers since 1986.

Instead, he walked out of Kansas State with a foundational win for his vast rebuilding effort.

Jarret Doege threw for 234 yards and three scores in place of Austin Kendall, and Hakeem Bailey made the play of the game when he picked off the Wildcats' Skylar Thompson in the closing seconds, allowing the Mountaineers to escape with a 24-20 victory Saturday night.

''This is a huge win. It felt like a long time coming,'' Brown said. ''Kind of been knocking on the door. I really felt like we'd be in a position at some point to win a game that maybe we shouldn't have. This is big for our program, big for our players and I'm proud of our guys.''

The Mountaineers (4-6, 2-5 Big 12) hadn't scored more than 17 points in their last four games, prompting the change at quarterback. Doege, who hadn't started since last November when he was still at Bowling Green, responded by throwing all three of his TD passes on crucial third downs.

The biggest? A 50-yard heave on third-and-22 that gave the Mountaineers the lead late.

''I was just thinking, `Get through my progression,''' Doege said, ''but I forced out and I saw him wide open and luckily got it off right before I got hit. I didn't know if he caught it until I looked up and saw him in the end zone.''

The Wildcats (6-4, 3-4) had plenty of chances to answer, but they turned the ball over on downs and then punted before their final drive. Thompson led them briskly downfield, but his second-down throw floated in the wind whipping out of the south and Bailey outjumped the intended target.

West Virginia then ran out the clock on the win and its five-game losing streak.

''We challenged them hard this week,'' Brown said, ''and the guys that have been in our program for a long time. ... We only get 12 of the these so you have to come to play.''

The Wildcats, who almost never altered their look under Hall of Fame coach Bill Snyder, donned a throwback uniform to the 1988 with white helmets and script ''Cats'' across them.

Perhaps they should have chosen a season in which they didn't go 0-11.

Thompson was 24 of 39 for 299 yards with a touchdown and two interceptions, and Kansas State had trouble moving the ball all night against a team that allowed 38 points to Texas Tech last week.

The Wildcats ran 32 times but averaged just 3.2 yards per attempt.

''When we struggle to run the ball it affects the rest of the offense,'' said the Wildcats' James Gilbert, who led the way with 60 yards rushing and a touchdown.

The Mountaineers' season-long growing pains appeared to continue right from the start, when they went three-and-out on offense and gave up a 68-yard TD pass on their first play on defense.

It was hardly a harbinger of the first half.

West Virginia answered with a 75-yard drive, finished off by Doege's touchdown pass to George Campbell. And when the Wildcats answered with a field goal, the Mountaineers reached the end zone again - though not without a bit of help from the officials.

West Virginia was held to a field goal that Casey Legg missed. But the crew ruled the Wildcats' Trey Dishon jumped the gun on the rush, giving the Mountaineers a fresh set of downs. They went nowhere on the first two plays before Campbell hauled in another touchdown pass.

Legg missed another field goal heading into the locker room, and the momentum appeared to have swung the Wildcats' direction in the second half. They opened it with a long, time-consuming touchdown drive to take a 20-14 lead midway through the third quarter.

They were never able to shake loose, though.

Kansas State was forced to punt on each of its next two possessions. Legg drilled a 51-yard field goal after missing a chip-shot late in the first half, and a few minutes later Doege took advantage of a major coverage lapse on third-and-22 to throw a 50-yard touchdown pass to Bryce Wheaton.

That turned out to be all the points the Mountaineers needed.

''Obviously a disappointing loss - a game West Virginia deserved,'' Kansas State coach Chris Klieman said. ''They outplayed us and, that being said, we had an opportunity late in the game to almost steal a victory. Disappointed in a number of things but obviously you have to move on.''

THE TAKEAWAY

West Virginia was desperate for some kind of spark, so Doege got the call. He was plenty shaky in his first start since last November, but he also made a couple of crucial plays when they mattered.

Kansas State came out flat after a gut-wrenching last-second loss at Texas last week. The Wildcats have now lost two straight after a three-game win streak highlighted by an upset of Oklahoma.

UP NEXT

West Virginia plays its home finale against Oklahoma State next Saturday.

Kansas State visits the Red Raiders for its final road trip next Saturday.

---

More AP college football: https://apnews.com/tag/Collegefootball and https://twitter.com/AP-Top25

Copyright 2019 by STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.