North Carolina (5-2, 1-2 Atlantic Coast Conference) had outscored its opponents by a combined margin of 42-3 in the first quarter before the Hurricanes rolled into town.
But Miami (3-3, 1-2) had a 17-0 lead after one quarter and extended its advantage to 27-3 late in the first half.
''It was a little bit shocking,'' North Carolina safety Matt Merletti said. ''Everyone was really up for this game, and then we had the wind knocked out of our sails a little bit. And so fast.''
For Miami, Jacory Harris passed for 267 yards and three touchdowns. The Hurricanes nearly lost their 24-point lead, surviving a sluggish second half for their first road win under Al Golden.
Miami, which gained 263 of its 311 total yards in the first half, avoided the first 0-3 start in league play in program history. The Hurricanes also picked up their first win in five tries at North Carolina.
Renner passed for 288 yards and two touchdowns for the Tar Heels.
Giovani Bernard rushed for 110 yards and a touchdown, becoming the first North Carolina player to rush for at least 100 yards in five consecutive games since Ethan Horton in 1984.
The Tar Heels scored two fourth-quarter touchdowns, cutting Miami's lead to 30-24 on a 20-yard catch by Reggie Wilkins with 46 seconds remaining. Curtis Campbell recovered the onside kick for North Carolina after Miami's LaRon Byrd was unable to secure the ball.
North Carolina moved the ball to Miami's 30 before Spence sacked Renner. The Tar Heels had a final play from the Miami 37, but a pass to Bernard with laterals to Erik Highsmith and Jheranie Boyd was stopped after a 13-yard gain.
The Tar Heels finished with 429 total yards, although 183 came in the fourth quarter against a softened Miami defense.
''We did not have any rhythm all day,'' Renner said. ''But we came back to fight, and that's a credit to our character.''
Miami's Lamar Miller entered the game as the ACC's leading rusher, but his streak of five consecutive 100-yard games ended. He managed just 29 yards on 16 carries.
Miami found other ways to move the ball, jumping on the Tar Heels through the air.
Harris marched the Hurricanes 71 yards for a touchdown on the game's opening drive, capping the 13-play series with a 4-yard scoring pass to Mike James.
North Carolina's T.J. Thorpe lost a fumble on the ensuing kickoff, setting up the Hurricanes on the UNC 27. Harris found Tommy Streeter, who got open deep after an end-around fake to Travis Benjamin, on the next play for a touchdown.
''Turnovers and big plays were the difference in the game,'' North Carolina coach Everett Withers said. ''We can't give up a big play and then turn the ball over to such a good team.''
After North Carolina's Thomas Moore kicked a 20-yard field goal to cut Miami's lead to 17-3, the Hurricanes answered with a field goal of their own.
Then they capitalized after a 13-yard punt by North Carolina's Thomas Hibbard gave them the ball at UNC's 40. Harris connected with Benjamin on a deep pass down the right sideline for a 30-yard touchdown and a 27-3 advantage.