Harrison Barnes shook off his nagging ankle injury and a series of undersized defenders to help No. 5 North Carolina take charge in the second half. He just couldn't finish off No. 10 Duke.

Barnes scored 19 of his 25 points after halftime for the Tar Heels in their 85-84 loss Wednesday night. Barnes, who sprained his left ankle against Wake Forest last week, missed all four of his shots in the first half but went 8-for-12 in the final 20 minutes.

"I wasn't able to do anything I wanted to do to the full extent," Barnes said of his ankle injury. "Even little things like running up and down the floor. I just tried to do what I could to help the team."

He appeared to have North Carolina on the way to a win when he hit a jumper for an 82-72 lead with 2:38 left. But the Tar Heels stumbled to the finish and freshman Austin Rivers made them pay with a buzzer-beating 3-pointer for the win.

It didn't appear the Blue Devils had a good defensive matchup for the 6-foot-8 sophomore, so Duke coach Mike Krzyzewski used 6-1 point guard Tyler Thornton along with Rivers and Andre Dawkins (both 6-4) for stretches against Barnes. It worked early before Barnes got going — only to see Rivers come up with a memorable shot that will live on in the lore of the rivalry.

"It's terrible to be in control of the game, up 10, and then lose on a last-second shot," Barnes said. "That's just a terrible way to lose."

For Duke, Rivers scored a season-high 29 points and hit six 3s, the last over 7-footer Tyler Zeller with the Blue Devils (20-4, 7-2) trailing by two in the final seconds. The ball swished through the net, sending Rivers running down the court in celebration while the rest of his teammates gave chase before mobbing him in front of a stunned UNC crowd.

It also ended UNC's school-record 31-game home winning streak.

Zeller added 23 points and 11 rebounds for the Tar Heels (20-4, 7-2). But the senior missed two free throws in the final minute, including one with 13.9 seconds left that set up Rivers' winning shot.

It was a finish befitting the rivalry, from Rivers' shot to Barnes' second-half surge to a strange play in which Zeller accidentally batted the ball into the Duke basket on a rebound attempt, bringing the Blue Devils within a point with 14.2 seconds left.

From the start, the Blue Devils seemed determined to rely on the 3-point shot to offset the Tar Heels' dominance inside. They hit plenty early and led by eight in the first half, then cooled off as the Tar Heels charged out of halftime to take control and lead by 13 points.

In the end, however, the Blue Devils' shooters warmed up just in time to stop North Carolina's long home winning streak.

First Seth Curry drained a 3 that made it 82-78 with 1:48 left. Then Ryan Kelly followed with a jumper off his own missed 3 that closed the gap to 82-80. Then, after Zeller hit a free throw, Kelly launched a long shot that appeared to be a 3 over John Henson. As the ball was falling short of the rim, Zeller tried for the rebound but accidentally deflected the ball up and into the basket to cut the deficit to 83-82.

Then again, North Carolina probably never should've let it come to that.

After trailing most of the first half, the Tar Heels ran off a 14-4 run to start the second half and build a 13-point lead. Barnes had a pair of baskets followed by a 3-pointer off a crosscourt pass from Kendall Marshall for a 57-44 lead with 15:08 left.

The Tar Heels maintained at least a seven-point lead until the final minutes. They shot 59 percent in the second half, but went just 8 for 15 from the foul line after halftime to let this one slip painfully away.