Wilson was 25-for-38 for 343 yards and the Wolfpack (4-5, 1-4) made just enough plays to secure their second win against a Bowl Subdivision opponent. Both teams combined for 752 total yards.
Wilson overcame a career-worst three interceptions with touchdown tosses of 17 yards to George Bryan, 35 yards to Donald Bowens and 18 yard to Darrell Davis. Wilson and Jamelle Eugene each had 2-yard scoring runs.
Torrey Smith returned a kickoff 82 yards for a touchdown, the school-record third of his career. Alex Wujciak returned an interception 70 yards for a score, while Davin Meggett and Chris Turner had 1-yard TD runs for Maryland (2-7, 1-4).
Nick Ferrara's 31-yard field goal pulled the Terps within seven with 4:56 remaining, then got the ball back with 59 seconds left. Backup quarterback Jamarr Robinson, filling in for the injured Turner, led them to the 34 with 22 seconds left but Michael Lemon sacked him with about 15 seconds left and then pressured him as he threw incomplete on the final snap.
Maryland has four straight and lost seven of eight.
Turner was 12 of 19 passing for 135 yards, but left late in the first half with an apparent left leg injury and didn't return. For a while, the offense seemed to go with him.
Robinson finished 5 of 11 for 27 yards. The Terps, who without injured Da'Rel Scott have dropped near the bottom of the ACC in rushing offense, had nine total yards in the third quarter.
This one shaped up as a shootout because in recent weeks, neither team seemed to show much interest in taking care of the ball or playing defense.
The Terrapins entered ranked 11th in the ACC in both total defense and against the pass. The injury-riddled Wolfpack allowed their previous three opponents to gain at least 480 total yards and score at least 45 points. N.C. State - which has lost 12 injured players for the season - was 11th in the league in turnover margin, ahead of only Maryland.
And that's exactly how it unfolded, with defensive end Willie Young intercepting Turner on the game's first play and Wilson hitting Bryan over the middle for a score 52 seconds into the game. Maryland countered with a 10-play drive that ended 3 1/2 minutes later with Meggett's 1-yard plunge.
It was a day of extremes for Wilson, who has thrown 10 touchdowns in three games. The all-ACC quarterback threaded one ball past defensive back Anthony Wiseman to Bowens down the right sideline for his second score.
One possession later, Wujciak jumped in front of his fourth-and-6 attempt and raced down the right sideline for a TD. Then, after leading the Wolfpack deep into Terp territory late in the half, he was picked off in the end zone with 38 seconds left. State had 301 total yards at halftime and led 24-21 at the break.