Mansfield wasted early chances before taking the lead with a penalty to go in with the advantage at the break, but paid dearly for poor defending after the break.
Wrexham hit back with three quick goals as the young Stags lost confidence and collapsed, finally letting a fourth in at the end.
It could have been different if early chances had been taken, but Mansfield's luck was out as Gareth Jelleyman shot over from an early effort and Jonathon D'Lareya saw a shot parried by home keeper Michael Ingham with Richie Barker heading against the post from the rebound.
Mansfield forced four corners in the first nine minutes and from another flag-kick Adam Birchall crossed to set up Stephen Dawson for a low shot that Ingham saved well.
Another effort from Alex Baptiste was deflected for a corner.
It was kick and rush for Wrexham with Mansfield changing their formation to string five across midfield and set the pace. Another shot from Birchall was blocked by defenders before Wrexham broke away for Darren Ferguson to try a shot that Kevin Pressman turned round the post.
Rhys Day wasted another chance with a weak header before Mansfield took the lead with a penalty. Barker stepping up to beat Ingham from the spot.
Mansfield should have added another when they broke quickly with Giles Coke and Birchall well placed in front of goal, only for Barker's pass to go too far and beyond the far post.
Wrexham came out with more purpose in the second half and Danny Williams headed them level from Matt Crowell's right-wing corner.
Three minutes later Jonathan Walters set up Lee McEvilly to put the home side in front sweeping the ball in from eight yards.
Walters added Wrexham's third with his fifth of the season as he exchanged passes with Ferguson and stabbed the ball home.
Mansfield's defence was now ragged in a dramatic change of fortunes.
Mansfield felt they should have had another penalty when Williams checked sub Simon Brown inside the box and then Barker had a shot blocked by Dennis Lawrence.
Finally Mark Jones wrapped it up with a cheeky chip over Pressman and into the back of the net.