CHAPEL HILL, N.C. (AP) Another big victory was slipping away from North Carolina State. Because the Wolfpack finally learned how to finish a game, their season isn't finished just yet.

Jaylen Samuels ran for one touchdown and threw for another on a trick play, and N.C. State held on to upset rival North Carolina 28-21 on Friday, earning bowl eligibility while also locking up a division title for Virginia Tech.

It's been a frustrating season for the Wolfpack (6-6, 3-5 Atlantic Coast Conference), who seemingly had victories in hand against a pair of nationally ranked division rivals - Clemson and Florida State - only to let them get away.

''It definitely makes you feel the worth of all your work,'' coach Dave Doeren said. ''We're playing every game but one - Louisville - for four quarters, toe to toe, with every team. We haven't won enough of them. I agree. But we are so much more competitive than we've ever been.''

In what at times seemed like a replay of N.C. State's 35-7 rout here two years ago, Matt Dayes rushed for 104 yards and two touchdowns. The second of those put the Wolfpack up 21-0 early in the second quarter.

Samuels threw a 59-yard touchdown pass to Stephen Louis on a trick play on the opening drive, and ran 4 yards for the TD that made it 28-7.

Mitch Trubisky threw three touchdown passes for the Tar Heels (8-4, 5-3), including a 48-yarder to Bug Howard that made it a seven-point game with 7:52 left. But on their next possession, they were stopped on downs near midfield with 3:10 to go and N.C. State ran out the clock - with backup quarterback Jalen McClendon sealing it with a 14-yard run on third-and-5 with about 2 minutes left.

''It's about these players and these coaches hanging together amid a lot of heartbreaking days and negativity and doubt,'' Doeren said. ''Guys just kept fighting with each other and for each other and they knew where our program is headed. ... Today was about mastering ourselves and finding a way to win and doing it against our rival.''

The Tar Heels, 10 1/2-point favorites, needed a win and a Virginia Tech loss to Virginia to earn a second straight ACC championship game berth. This loss locks the Hokies into next week's matchup with No. 4 Clemson in Orlando, Florida.

THE TAKEAWAY

N.C. State: This should take some heat off Doeren, who had been drawing criticism from a segment of the fan base after going 8-23 in ACC games before this one. In four years, Doeren now has won almost as many ACC games at UNC's Kenan Stadium (two) as he has at his own Carter-Finley Stadium (three).

North Carolina: By losing to a pair of neighborhood rivals - both of whom were under .500 at the time - the Tar Heels blew their chance to repeat as Coastal champions. They lost to Duke and N.C. State in the same season for the first time since 2003, and in some ways this game felt like an extension of the loss in Durham - with the Tar Heels managing a combined 13 points in the last two quarters of that game and the first three of this one.

''That's on us,'' running back Elijah Hood said about the team's lack of focus. ''We've got to go out there - we're on the football field, the ball's coming to us, we've got to make that catch. There's really no excuse for it.''

THE BRAWL

Things got chippy late in the first half when UNC DT Jalen Dalton was ejected for throwing a punch during a fight that cleared the benches. The skirmish broke out near midfield with about six minutes left in the half after N.C. State's Matt Dayes fumbled. The ball squirted about 20 yards downfield with at least four players trying to scoop it up. That led to a pileup near midfield, and Dalton appeared to hit Wolfpack lineman Terronne Prescod. Later in the skirmish, UNC coach Larry Fedora unsuccessfully tried to restrain Dalton by the back of his collar. After a review, the pass was ruled incomplete.

KEY MOMENT

North Carolina trailed 21-7 at halftime and started the second half by recovering an onside kick to seemingly seize momentum. But during an official review, it was determined that Ayden Bonilla had delivered an illegal block before Anthony Ratliff-Williams recovered the ball. That wiped out the recovery and required a rekick, and N.C. State then chewed up 6 1/2 minutes with a 14-play drive that ended with Samuels' touchdown run that made it 28-7.

UP NEXT

N.C. State: This victory earned the Wolfpack a spot in a bowl game, and on Dec. 4 they'll find out who and where they play.

North Carolina: The Tar Heels won't have to worry about flying to Orlando next week for the ACC championship game. Instead, they'll await their bowl opponent.

---

Follow Joedy McCreary at http://twitter.com/joedyap.

---

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

Copyright 2016 by STATS LLC. Any commercial use or distribution without the express written consent of STATS LLC is strictly prohibited.