The Panthers (4-6, 2-4) had a final chance, but quarterback Chad Voytik fumbled on a hard hit from Malik Simmons near midfield. Shakeel Rashad grabbed the loose ball with 15 seconds left to secure the win.
Marquise Williams turned in a huge performance for UNC, which trailed 14-0 before getting its offense rolling. Williams ran for 122 yards and three touchdowns, and also threw for 276 yards and a score.
ACC leading rusher James Conner ran for 220 yards and four touchdowns for the Panthers, including the 22-yard score with 3:33 left for a 35-34 lead.
But that was more than enough time for the Tar Heels, who had been in this exact position before less than a month earlier.
In the last home game, Georgia Tech went ahead on a 75-yard reverse with 3:07 left, before Williams led the go-ahead drive for the winning score with 11 seconds to go.
Logan had the winner there, too, scoring from 2 yards out for the 48-43 win on Oct. 18.
The teams entered this one in the same position, each needing two wins in the final three games to become bowl eligible. Now the Tar Heels are a win closer while the Panthers must beat both Syracuse and Miami to get there.
Conner scored from 56 yards out on the game's first possession, then added scoring runs of 16 and 2 yards before breaking four tackles and dragging two defenders the final few yards on his last TD.
Along the way, Conner set ACC and program records for most season rushing yards by a sophomore.
Tyler Boyd also had a big day for Pitt, catching five passes for 160 yards and a 50-yard score midway through the second quarter.
Ryan Switzer scored on a 63-yard catch-and-run touchdown early in the third quarter for the Tar Heels, while Logan finished with 92 yards rushing.
The teams each cracked the 500-yard mark and combined for 1,025 total yards of offense.
North Carolina played without tailback Romar Morris, who was suspended one game after a recent DWI arrest. The Tar Heels were also without linebacker Travis Hughes due to an unspecified violation of team policy.