The win clinched the ACC Coastal Division title for the Blue Devils (10-2, 6-2 ACC), who advance to the conference championship game next week against unbeaten Florida State.
Martin's decisive kick with 2:22 left in the game was followed up by an interception by DeVon Edwards that iced the win in the final seconds.
Anthony Boone completed 23-of-34 passes for 274 yards and connected with James Crowder for two Duke touchdowns. Edwards added to the Blue Devils' tally with a 99-yard kickoff return late in the second half.
Marquise Williams was 17-for-36 for 223 yards for North Carolina (6-6, 4-4). He connected on a TD pass to Quinshad Davis in the third quarter to pull the Tar Heels to within 24-22.