McCoy threw for 244 yards for the Longhorns, (3-2, 2-0), who will head into next week's game against Oklahoma with at least a share of first place in the Big 12.
McCoy led Texas on the winning 75-yard drive in just under 3 minutes. It was aided by two pass-interference penalties and two near fumbles at the 1 by Johnathan Gray.
Sam Richardson had 262 yards passing and Aaron Wimberly had 117 yards rushing and a touchdown for Iowa State (1-3, 0-1). The Cyclones dropped their 11th straight Big 12 opener - but none as heartbreaking as this one.
In a crucial game for both programs, momentum swung back and forth with every drive.
Iowa State's energy was seemingly squashed when McCoy found John Harris for a 44-yard touchdown strike to end the first half.
The Cyclones revitalized a near-sellout crowd with the longest pass play in school history.
Richardson found Quenton Bundrage on a simple slant, and Bundrage beat the Texas secondary for a 97-yard score that gave Iowa State a 20-17 lead. Texas answered on a 6-yard TD run by Joe Bergeron - which was set up by a pair of pass-interference calls that Iowa State fans also weren't too happy about.
Mike Davis then lunged at the knees of Iowa State's Deon Broomfield, drawing a personal foul that could end up being much more than that once the Big 12 reviews the tape.
Wimberly gave the lead back to the Cyclones after a fumble with 11:32 left. Cole Netten's 29-yard field goal made it 30-24 with 3:40 to go.
It wasn't enough though, as the Longhorns embarked on the winning drive that might end up saving their season.
Jackson Jeffcoat's interception with 8 seconds left sealed the win for Texas.
Gray had 89 yards rushing, including a 45-yard touchdown dash, for the Longhorns
McCoy started for the second time this season in place of the injured David Ash, who was out with concussion-like symptoms, and helped put Texas take a 10-0 lead before Iowa State rallied for 13 straight points.
McCoy got the Longhorns the lead back with a desperation heave. He flung the ball almost blindly into the end zone - and found Harris between three defenders to put the Longhorns up 17-13.
McCoy was far from perfect. But on a night when the Longhorns and Mack Brown desperately needed a win, McCoy did just enough to help give them one.
Take ABC13 with you!
Download our free apps for iPhone, iPad and Android devices