The Cowboys (9-0, 6-0 Big 12) matched the best start in school history and survived quite a scare from K-State (7-2, 4-2), which had three shots at the end zone in the final 12 seconds.
Collin Klein missed on 5-yard passes intended for Tyler Lockett and Chris Harper and then overshot Tramaine Thompson in the end zone as time expired. Oklahoma State's players rushed on to the field to celebrate, their national championship hopes still intact.
All-America receiver Justin Blackmon caught 13 passes for 205 yards and two touchdowns, atoning for his two-fumble game with a 54-yard touchdown catch with 4:47 remaining that pulled the Cowboys out of a 38-37 deficit.
He also caught the 2-point conversion for a 45-38 lead.
Kansas State responded right back with Lockett's 80-yard kickoff return and three straight runs by Klein, who barged in from 12 yards out to tie it up with 3:18 remaining.
It took Oklahoma State's quick-strike offense just four plays and 62 seconds to respond again. Weeden found Isaiah Anderson for a 33-yard gain, and Randle ran through a big hole on third-and-1 before dodging safety Jordan Zimmerman to waltz in for the game-winner.
Klein drove the Wildcats down for a chance to tie - or perhaps go for the win with a 2-point conversion - by converting a fourth-and-4 with a quarterback keeper and then connecting with Harper for 22 yards to set up first-and-goal at the 5-yard line.
With no time to rely on his potent running game, coach Bill Snyder called three straight passing plays but none got the job done.
Klein finished with 231 yards passing with one touchdown and one interception. He also ran for 144 yards and three scores.
Minutes after the game ended, the stadium shook from an apparent aftershock from a 4.7-magnitude earthquake earlier in the day.
The thrilling finish came after a wild back-and-forth game filled with turnovers and plenty of offense - nothing like what was on display in LSU-Alabama clash in the SEC that ended 9-6 in overtime.
While LSU will likely remain first when the BCS standings come out on Sunday, Oklahoma State will probably be the new No. 2.
With starting receivers Josh Cooper and Hubert Anyiam out, Tracy Moore set career-highs with nine catches for 146 yards for Oklahoma State.
Oklahoma State capitalized on Klein's fumble on the Wildcats' second play from scrimmage to strike first with Randle's 4-yard touchdown run, and it was soon 14-0 after Weeden hit Moore for a 44-yard gain to set up the Cowboys' second score.
Blackmon stutter-stepped at the line to get Nigel Malone on his heels, then caught Weeden's pass and stutter-stepped again to get past him for an 11-yard score.
Then the Cowboys' stars made a series of mistakes to let K-State get back in the game.
Blackmon fumbled on a punt return to set up Anthony Cantele's 37-yard field goal, then Weeden gave the ball right back by throwing a pick to Tysyn Hartman on a deep ball. Angelo Pease and Klein had short TD runs on Kansas State's next two possessions before another Weeden interception was returned 60 yards for a score by Allen Chapman.
Kansas State led 24-14 - the biggest home deficit this season for the Cowboys - then started piling up errors of its own.
James Thomas intercepted a pass that Klein threw into coverage and Brodrick Brown tipped. His 47-yard return set up Weeden's 5-yard TD pass to Moore on the next play. Then, instead of pinning Oklahoma State deep, Ryan Doerr's punt went out of bounds after only 19 yards and gave OSU good field position to drive for Quinn Sharp's 29-yard field goal and a 27-24 halftime lead.
The Cowboys were 1 yard away from claiming a 41-31 lead late in the third quarter when Blackmon fumbled for the second time in the game and Lyndell Johnson recovered in the end zone for Kansas State.