AMES, Iowa — For Iowa State, it felt like yet another inexplicable loss to Kansas State might be inevitable.

Then a fumble flipped in the air and fell right into Mike Rose's hands, and the Cyclones' bad luck against the Wildcats seemed to wash away.

David Montgomery ran for three touchdowns, including the winner with 4:34 to go, and 25th-ranked Iowa State rallied from 17 down in the fourth quarter to stun Kansas State 42-38 and snap a 10-game skid against the Wildcats on Saturday night.

Montgomery had 149 yards rushing for the Cyclones (7-4, 6-3 Big 12), who clinched their best-ever finish in the Big 12.

Down 38-21, Iowa State scored twice in just 1:44 early in the fourth — on Brock Purdy's short TD pass and a 21-yard fumble return by Rose after Willie Harvey forced it — to pull to 38-35.

The made a stop, and Montgomery's 18-yard touchdown run gave Iowa State an improbable lead.

"This team has never disappointed me," Iowa State coach Matt Campbell said. "We're not flashy. We're not pretty. But you better not count us out."

Kansas State's (5-7, 3-6) fate was sealed when a long pass to Dalton Schoen deep in Iowa State territory glanced off his fingertips with 1:20 left.

The Wildcats took control by going 92 yards on eight plays after picking off Purdy, opening up a 31-21 lead on Skylar Thompson's 9-yard TD pass to Chabastin Taylor late in the third. K-State's Kevion McGee then intercepted Purdy again, and Isaiah Zuber's second TD grab of the game made it 38-21 early in the fourth.

Purdy redeemed himself down the stretch though, finishing with 337 yards passing and two touchdowns in what Campbell said was his best game yet.

Thompson threw three touchdown passes and ran for a score, and Alex Barnes rushed for 184 yards and a TD for the Wildcats. Barnes rushed for at least 100 yards in his last four games, the longest such streak for a Wildcat since Darren Sproles had a five-game streak in 2003.

"I've never lost a ballgame that way. I'll have to dissect it," Kansas State coach Bill Snyder said. "I can't tell you what my feelings are right now."

THE TAKEAWAY

Iowa State: The Cyclones revival since the start of last season had been sparked by their defense. But the cracks that began to show in a win over Baylor and a loss at Texas developed into sink holes against the Wildcats. Iowa State's offense, bailed out so often by their teammates on the other side of the ball, finally returned the favor — and the defense showed up when it mattered.

K-State: If this proves to be Bill Snyder's final game, what a brutal way to go out. All the Wildcats had to do was protect a 17-point lead with 12 minutes to go bowling, but they couldn't do it.

SNYDER'S STATUS

K-State's 5-7 record is the worst since Snyder came back in 2009. Speculation has been rampant that the 79-year-old Snyder might step down, but he didn't address those rumors after the game. "That's the last thing on my mind right now," Snyder said when asked about his status.

WHY THE CYCLONES FELL BEHIND

Tarique Milton fumbled away a punt just before halftime, and it took the Wildcats 16 seconds to go 34 yards for a touchdown; a 6-yard pass from Thompson to Isaiah Zuber to make it 21-14. Kansas State, which struggled in the red zone all year, scored on all six of its trips inside Iowa State's 20.

DID THE BUTLER DO IT?

On the previous series, Iowa State appeared to take a 20-14 lead on a short TD pass from Purdy to Milton. But Hakeem Butler was called for offensive pass interference, and Connor Assalley then shanked a 38-yard field goal attempt. Butler also had a sure TD bounce off his hands late in the fourth quarter, but Montgomery bailed him out shortly thereafter. "David is the best player in the country to me," Butler said. "I tell him that every day, and he proved that." Butler finished with 144 yards on five catches.

HE SAID IT

"The chances of the ball just falling right in his lap like that and then returning it for a touchdown and quick scores like that after we were up 17 points, that was frustrating. We couldn't really get it going after that," Thompson said about Rose's fumble return.

UP NEXT

Iowa State hosts Drake of the FCS in a makeup for its canceled opener.

Kansas State's season is complete.