County took the lead when Irishman Ronan Murray blasted home his fourth goal of the season after a cross from Blair Adams was only half-cleared after 12 minutes.
But League Two Stanley, who held the Magpies to a goalless draw at Meadow Lane, came back fighting against Shaun Derry’s men.
Defender Rob Atkinson was denied by Northern Ireland keeper Roy Carroll while Shay McCartan blasted over the bar from six yards with the goal at his mercy.
However, after 44 minutes, McCartan made amends when he crossed into the area and skipper Luke Joyce stooped to head home the leveller.
Stanley continued where they left off at the break and turned the game on its head after 49 minutes against their higher-league opponents when, from a corner, the ball bounced around the area and came out to Carver who looped the ball over Carroll.
County came straight back and Magpies substitute Jake Cassidy had only been on the pitch a minute when he got the ball and beat keeper Jack Rose but his chip crashed off the crossbar and was cleared as he turned to celebrate after 57 minutes.
Derry made all his substitutions as they looked to avoid a cup upset but Stanley held firm and they now have a home tie against Yeovil in the second round.