Updated

The fouls just kept adding up for No. 18 North Carolina State.

With starters C.J. Leslie and Lorenzo Brown hampered by foul trouble, coach Mark Gottfried saw his team fall out of rhythm and become cautious in an 86-84 loss at Wake Forest on Tuesday night.

It certainly contributed to the Demon Deacons shooting 59 percent in the second half and playing aggressively against the backpedaling Wolfpack.

"It's a tough situation because obviously you want your best offensive players in the game yet you've still got to guard them," Gottfried said. "We just didn't do a very good job there as a team defending, but I do think our foul trouble put us behind the 8-ball."

Leslie and Scott Wood got into first-half foul trouble and neither player played even 10 minutes before halftime. Leslie picked up his third and fourth fouls in rapid-fire fashion with 17:26 left, then Brown was called for a charge for his fourth with 10:33 left.

Leslie played just 18 minutes as one of three players with four fouls, while Richard Howell fouled out in the final seconds. It all hit hard for a team that typically has only six players getting significant minutes of late.

"You've got guys in the game they're probably a little tired playing extra minutes and things like that," freshman Rodney Purvis said. "Once you look to the bench, you've got every guy that really gets into the game, they've got two fouls so it's hard to put them back in in the first with two fouls. It's a huge risk and it's just taking a gamble."

For Wake Forest, freshman Devin Thomas had a season-high 25 points, 14 rebounds and four blocks.

Travis McKie added 16 points for the Demon Deacons (10-8, 3-3 Atlantic Coast Conference), including two free throws with 3.4 seconds left that helped Wake Forest hold on down the stretch in a wild final 4½ minutes.

N.C. State led by 16 points in the first half and 12 at halftime only to see the Demon Deacons rally and push ahead to their own 10-point lead.

Then N.C. State (15-4, 4-2) managed its own comeback, closing the gap to a point with about a minute left. But ultimately, Wake Forest — a team filled with freshmen — did just enough to earn a win that sent their fans storming the court to celebrate.

This was a huge win for the Demon Deacons, who have done little other than struggle in three seasons under Jeff Bzdelik. That included losses to the Wolfpack here by 36 and 25 points in the past two meetings in Winston-Salem.

But Wake Forest is 3-0 at home in league games this season and managed to deny N.C. State its first 5-1 ACC start since 1988-89. It was also the Demon Deacons' first win against a team ranked in The Associated Press Top 25 since beating Georgia Tech in February 2010 under former coach Dino Gaudio, according to STATS LLC.

Rookie Codi Miller-McIntyre scored 15 points for the Demon Deacons, who led 82-72 with about 4 minutes left before the Wolfpack's final push made things interesting. N.C. State used a 10-1 run to close the gap and pull within 83-82 on Leslie's free throw with 1:01 to go.

But Leslie missed two free throws for the lead with 29.9 seconds left, then Scott Wood missed an open 3-pointer off an offensive rebound following Leslie's second miss. Then, after a free throw from C.J. Harris, the Wolfpack came up empty on two shots from inside the paint — one from Leslie while taking contact and a runner off a loose rebound by Purvis — with the chance to tie.

The Wolfpack had a final chance to tie or win after Leslie scored on a layup with 1.2 seconds left to cut it to two. Freshman T.J. Warren stole a long inbounds pass near midcourt, but his final desperate heave wasn't close as the horn sounded.

Purvis scored 18 points to lead the Wolfpack, who fell to 1-2 since upsetting top-ranked Duke on Jan 12.