CHAPEL HILL, N.C. (AP) North Carolina went from looking a step slow and struggling to keep Duke's touted freshmen off the boards to roaring out of halftime with an aggressive edge on the way to a rousing win.

Maybe the 21st-ranked Tar Heels just needed their fiercest rival to bring out something that had been missing for weeks.

Joel Berry II scored 21 points and UNC hung on late to beat the ninth-ranked Blue Devils 82-78 on Thursday night, capping an emotional performance that included a comeback from a dozen down in the first half.

The Tar Heels (18-7, 7-5 Atlantic Coast Conference) had recently emerged from their first three-game losing streak in four years by beating the only team (Pittsburgh) yet to win a league game. And they had struggled to find much of a confidence-building flow.

Until Thursday, with the Blue Devils (19-5, 7-4) in the Smith Center in front of a crowd operating at ear-ringing levels.

''Once everybody got going,'' said Kenny Williams, who matched his career high with 20 points, ''we proved to ourselves how good we can be.''

The Tar Heels had four players score at least 15 points, including Pittsburgh graduate transfer Cameron Johnson going for 18 points and 13 rebounds in his first taste of the Duke-UNC rivalry. And that helped the Tar Heels reverse a first-half rebounding struggle against Duke's bigger front line of Marvin Bagley III and Wendell Carter Jr., and dominate the glass after halftime.

''Everybody crashed the boards,'' said senior Theo Pinson, who had seven rebounds. ''We told them at halftime: Me and Luke (Maye) are going to do everything we can to keep Carter and Bagley off the boards. You have to come in and rebound.'''

UNC finished with a 28-17 rebounding advantage after halftime that included 15 offensive rebounds, a sign of how the Tar Heels were outworking the Blue Devils as they turned the game out of the break.

''The start of the second half, they played great,'' Duke coach Mike Krzyzewski said, ''and we were awful.''

The Tar Heels opened the second half on a 16-2 run to erase what was left of Duke's early lead and go ahead for good. UNC led 61-51 at the end of its run and played from in front the rest of the way.

''We turned a four-point lead into a 10-point deficit,'' Duke senior Grayson Allen said. ''That's hard to come back from against a really good team.''

The Tar Heels were tough enough to win despite going just 2 for 18 from the field in the final 8 minutes, while they tied a program record by having just two turnovers for the entire game.

Duke got as close as 74-71 late, and freshman Gary Trent Jr. (team-high 16 points) missed a corner 3-pointer for the tie with 3:33 left. Johnson responded with a huge 3 for the Tar Heels, who got Pinson's dunk off the press break with 11.1 seconds left to all but seal it.

BIG PICTURE

Duke: The Blue Devils were coming off Saturday's loss to a St. John's team that was 0-11 in the Big East - the Red Storm stunningly followed that with a road upset of No. 1 Villanova - in a performance that Krzyzewski described as ''disgusting'' and not up to the program's standards. It looked like Duke was ready to bounce back in the first half, but the Blue Devils couldn't match UNC's second-half surge.

UNC: Thursday's run after halftime - and their composure for much of the second half, for that matter - was some of the best basketball the Tar Heels have played in weeks.

OUTSIDE PUNCH

Williams' 20 points included six 3-pointers, tying the record for a UNC player against Duke held by current assistant coach Hubert Davis since 1992.

POINT PLAY

Berry overcame a 7-for-20 shooting day and finished with six assists, four rebounds and two steals in his matchup with touted freshman point guard Trevon Duval. Duval had nine points on 2-for-9 shooting before fouling out with 3:23 left, including a flashy first-half dunk that fired up Berry.

''That's why I started picking him up full-court and just trying to get into him,'' Berry said, ''letting him know that you're still a freshman and I don't care how good you are, one and done, that doesn't scare me. I'm a competitor and I'm going to come to compete each and every day.''

UP NEXT

Duke: The Blue Devils visit Georgia Tech on Sunday.

UNC: The Tar Heels get another rivalry game against North Carolina State - even though Berry said this week he didn't consider the Wolfpack a rival - on Saturday in Raleigh, part of a stretch of three games in five days.

---

More AP college basketball: https://collegebasketball.ap.org and https://twitter.com/AP-Top25

---

Follow Aaron Beard on Twitter at https://twitter.com/aaronbeardap

Copyright 2018 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.