The Wildcats (7-5) fell behind 20-7 in the first half after Lance Dunbar rushed for 161 yards and two long touchdowns in the first quarter alone.
Dunbar finished with 270 yards and three touchdowns for the Mean Green (3-9), who are leaving 58-year-old Fouts Field and moving across Interstate 35 into a new $78 million stadium next year.
Kansas State finally went ahead 21-20 on Carson Coffman's touchdown pass with 5 seconds left in the first half. The Wildcats scored twice early in the third quarter to build a cushion that withstood a wild second half.
The half-full stadium had at least as much Wildcat purple as Mean Green, but the Kansas State fans didn't have much to cheer for most of the first half.
Running through huge holes, Dunbar had a 52-yard scoring run on the fourth play of the game and went 63 yards for a 20-7 lead with 3:33 left in the first quarter.
In his final audition for the permanent job, interim North Texas coach Mike Canales did plenty of arm-pumping trying to keep his team in front. But Kansas State's varied rushing attack kept coming.
Backup quarterback Collin Klein came off the bench in the third quarter for a 6-yard scoring run and a nifty pitch to Braden Wilson for a 1-yard TD. Thomas took several direct snaps for runs that helped set up both scores.
The rest of the game mocked the legacy of Greene, the former Pittsburgh Steelers star who won four Super Bowls as part of the stingy Steel Curtain defense.
Dunbar went 36 yards to finish a 79-yard touchdown drive that pulled the Mean Green within 35-27, but Thomas answered with his second touchdown, a 3-yard run that capped a 56-yard march.
The teams traded 90-plus-yard kickoff returns that left Kansas State in front 49-34 early in the fourth quarter before North Texas drove another 77 yards to pull within 49-41. Dunbar scored from 17 yards on a fourth-down shovel pass from backup Chase Baine on the first snap after starter Riley Dodge left on a stretcher with a neck injury.
Dodge spent about 10 minutes on the field but had full movement before going to a hospital for X-rays.
Both defenses stiffened late in the fourth quarter, but not before the teams combined for 909 yards.
The final play at Fouts Field was a Hail Mary toss from Baine that traveled 60 yards before Kansas State intercepted it in the end zone.