The dramatic conclusion ended North Carolina's 31-game home winning streak and created a three-way tie atop the Atlantic Coast Conference.
Duke trailed by 10 with 3:30 to play, but closed within one with 18 seconds left when Mason Plumlee scored on a tip-in.
North Carolina's Tyler Zeller was fouled with 14 seconds remaining, but he made only one of his two attempts from the line.
That set up Rivers for his 3-pointer from the right wing, giving him a career-best 29 points for the contest.
Six of Rivers' nine field goals came from beyond the arc. Duke made 14 3-pointers overall. Ryan Kelly and Seth Curry both had 15 for the Blue Devils, who bounced back from an overtime loss to Miami on Sunday.
Duke improved to 20-4 and, at 7-2 in league play, is tied for the league lead with Florida State and North Carolina.
Harrison Barnes scored 25 points for the Tar Heels (20-4) and Zeller had 23 points with 11 rebounds.
North Carolina made four more field goals than did Duke and also hit four more from the line. The Tar Heels, however, converted only one 3-point shot.
Scarlett Johansson steps out with fiance after pregnancy reveal
Susan Sarandon 'very excited' about daughter's pregnancy