Centre-back John McCombe had celebrated a recall with his first two goals for Mansfield that looked to have won it for them.
But sloppy defending at the death saw Kai Naismith net three mintues into added time and James Gray snatch an unlikely win two minutes later for Stanley.
It was a game that lacked any real quality between two sides low on confidence. But McCombe twice netted from James Jennings corners to give Mansfield hope of a first home win in eight.
For the opener McCombe jumped to meet Jennings' right-wing corner only to see the ball thud against the bar. But the centre-back quickly followed up to ram the ball high into the net from close range for his first goal for the club.
Gray should have done better on a couple of occasions, lashing a Piero Mingola nod-down well over with time and space and also prodding the ball to no one when he was in a good position to shoot..
Nevertheless the visitors were level out of the blue three minutes into the second half. Naismith's effort from the edge of the box seemed to carry little threat until a big deflection off a defender took it agonisingly wide of Alan Marriott and inside the post.
But just as the home fans were beginning to show their frustration McCombe struck again in the 68th minute. Jennings sent in a corner that McCombe met with a fierce shot which was blocked on the line. But McCombe made no mistake with his powerful follow-up from 12 yards.
With Stanley pushing, Stags should have sealed it near the end when Daryll Westlake went clear on the break only to see Marcus Bettinelli save with his legs.
With the game looking won, a McCombe clearance came out to Naismith who poked a low finish back into the net.
And with Mansfield reeling, Stanley struck again as another loose ball from a McCombe tackle rolled towards Gray who lashed a superb finish past Alan Marriott to provoke boos all round the ground