The Terrapins (6-2, 3-1) got the ball on their own 8 with 4:50 remaining and moved 89 yards before Egekeze's winning kick. Chris Turner went 3-for-4 on the drive, including a 31-yard completion to running back Davin Meggett on a third-and-10 from the Wolfpack 35.
Turner than ran the ball to the middle of the field to set up Egekeze's second field goal of the game.
It was the sixth straight home win for Maryland, which had to overcome an inspired North Carolina State team and miserable weather. The victory made the Terrapins bowl-eligible and kept them tied atop the league's Atlantic Division.
North Carolina State (2-6, 0-4) has lost four straight.
Da'Rel Scott ran for 163 yards and a touchdown for Maryland, which again struggled as a favorite. The Terrapins have beaten three ranked teams this season but lost to Middle Tennessee State and Virginia.
Coming off a 26-0 win over Wake Forest, Maryland gave up touchdowns on North Carolina State's first two possessions and yielded 342 yards in offense. The Wolfpack held the ball 12 more minutes than the Terrapins and ran 15 more plays.
Russell Wilson went 18-for-26 for 187 yards and two touchdowns for N.C. State, the only team in the ACC without a league win.
With the score tied at 24 early in the fourth quarter, Maryland retained possession after the Wolfpack were called for a personal foul on a punt. Scott then ran in from the 12, but the play was nullified because of holding. Three plays later, Egekeze missed a 39-yard field goal.
The senior kicker did redeem himself at the end.
Maryland opened the second half by covering 67 yards in four plays to take a 24-17 lead. Scott ran three times for 43 yards, including a 24-yard touchdown run.
Wilson then scrambled for 27 yards on a third-and-9, which led to his 7-yard touchdown pass to Darrell Davis that tied the game for a third time.
In a first half that ended 17-all, Wilson threw for 133 yards -- 2 more yards than Maryland could muster.
The Wolfpack took the opening kickoff and used nearly 8 minutes with a 14-play drive. Wilson went 3-for-3 for 38 yards before Andre Brown scored on a 1-yard dive.
Maryland answered with a 66-yard drive. Turner's 13-yard touchdown pass to tight end Dan Gronkowski came on the only third down of the possession.
The rain picked up at that point, but it didn't slow the North Carolina State offense. Wilson threw a 29-yard pass to Jamelle Eugene and hit Jarvis Williams for a 4-yard touchdown to cap a 73-yard drive.
Maryland couldn't keep pace, getting a career-long 47-yard field goal from Egekeze to close to 14-10. But Brown opened N.C. State's third possession by losing a fumble, setting up a 1-yard touchdown run by Meggett.
Late in the half, Maryland's Danny Oquendo fumbled the wet football on a punt return. After the Wolfpack recovered at midfield, Josh Czajkowski kicked a 28-yard field goal as time expired.