The Hawkeyes sent the game to overtime when Stanley and running back Akrum Wadley teamed up on a 46-yard pass play with 1:06 to go.
Iowa held Iowa State to a 30-yard field goal on the opening possession of overtime before Stanley threw his fifth touchdown pass of the day.
Iowa (2-0) had tied the game at 31 with 5:16 left, but the Cyclones needed just two plays to go back in front. Iowa State quarterback Jacob Park connected with Hakeem Butler on a 74-yard pass play to put the Cyclones up 38-31.
Stanley completed 27 of 41 passes for 333 yards with no interceptions. Wadley ran for 118 yards on 28 carries, also catching four passes for 72 yards, including his scoring dash down the left sideline.
Park was 25-for-46 for 347 yards and four touchdowns. David Montgomery ran for 112 yards on 20 carries. Wide receiver Allen Lazard had five catches for 128 yards and two touchdown receptions for the Cyclones (1-1).
Iowa cut its deficit to 31-28 on a 15-yard pass from Stanley to Smith-Marsette with 6:25 to go.
On the first play of the ensuing drive, the Hawkeyes' Parker Hesse intercepted a Park pass and returned it to the Iowa State 5. But Iowa had to settle for a field goal, tying it 31-31 with 5:16 remaining.
Iowa appeared to take control after halftime, going up 21-10 midway through the third quarter.
But the Cyclones responded, scoring twice in the final 4:37 of the quarter. The Cyclones went ahead 24-21 when Butler took a Park pass 30 yards for a touchdown on a fourth-and-1 play.
Iowa State made it 31-21 on a 7-yard run by Montgomery with 11:46 to go.
Iowa took its first lead late in the first half on a 17-yard touchdown pass from Stanley to receiver Matt VandeBerg. The pass capped a 10-play, 91-yard drive on which Wadley had 52 yards rushing.
Wadley had 78 yards on 12 carries in the first half.