– Oklahoma State got the victory it needed, just not the style points.

Backup quarterback J.W. Walsh threw a 7-yard touchdown pass to Jeff Carr with 3:06 left Saturday, giving No. 5 Oklahoma State a 35-31 victory over Iowa State and keeping the unbeaten Cowboys in playoff contention.

Oklahoma State (10-0, 7-0 Big 12) trailed 24-7 and 31-21 before rallying for a victory that might not look impressive but was critical in jockeying for a spot in the College Football Playoff.

It was the fifth time in as many road games this season that the Cowboys pulled it out after trailing in the second half.

"I'm sure TV loves us," OSU coach Mike Gundy said. "It's a good win by the team. As we all know, coming up here and playing is never really easy."

Walsh drew the Cowboys to 31-28 with a 16-yard touchdown run early in the fourth quarter and OSU drove 84 yards in 11 plays for the winning score after forcing a punt.

Starter Mason Rudolph got Oklahoma State to the Iowa State 7 and Walsh, usually the team's running quarterback, took it from there. He hit Carr with a swing pass on the left side and two blocks sprung the freshman to the end zone.

"You don't win without having some maturity and a relentless football team," Walsh said, "and we've been able to attain those things very well."

Quarterback Joel Lanning had helped keep Iowa State (3-7, 2-5) ahead for most of the game, running for two touchdowns and passing for another. He and the Cyclones had two chances after Carr's score but gave up the ball on downs and then turned it over with an interception after getting it back.

Lanning ran for nice gains on read options and scrambles and did just enough with his passing to keep the Cyclones moving.

He carried 14 times for 130 yards and scored on runs of 24 and 21 yards.

It just wasn't enough. One reason was that Oklahoma State controlled the ball with time-consuming scoring drives in the second half.

"I remember looking up at the clock and Okie State had one possession in the third quarter and we had one and there was like three minutes left in the quarter," Lanning said. "It was crazy."

Lanning also completed 11 of 22 passes for 162 yards, including a 24-yarder to Allen Lazard for a TD in the first half, when Iowa State scored three touchdowns and kicked a field goal on its first four possessions.

Rudolph completed 24 of 36 passes for 327 yards and a touchdown — a 16-yarder to Marcell Ateman, who made a leaping catch in the far left corner of the end zone to tie it at 7-all.

Ateman finished with career highs of eight catches and 132 yards.

"Mason made some great throws, and J.W. is a tough kid," Ateman said. "Both are great guys and a times [Iowa State] struggled to stop them."