Substitute Liam Dickinson scored with his first touch as he headed over luckless keeper Michael Ingham deep into injury time to secure the points for Stockport County.
The Hatters striker got on the end of a header by Tes Bramble from an Adam Griffin free-kick and nodded over Ingham into the roof of the net.
Wrexham had the better of a lively first half with Matt Done squandering the first chance as he drove a 20-yard free kick straight at keeper Wayne Hennessey.
Next striker Marc Williams tried a long-range drive that flew high over the crossbar and Lee McEvilly scooped over from close range.
In the next raid, Chris Llewellyn sent Ryan Valentine away on the left to set up Done for a deep cross that went straight to the keeper.
Midfielder Robert Garret, making his Wrexham debut on loan from Stoke City, had an impressive game but was way off target with a shot from near the centre circle.
Hennessey had to dive full length to deny McEvilly, whose shot from Llewellyn's left-wing cross seemed certain to fly inside the right post.
The game was 20 minutes old before Stockport made their first attempt on goal with David Poole testing Ingham with a dipping shot from just outside the area.
Hennessey was in action again holding Danny Williams' header from Done's corner.
Paul Mitchell made a good opening with a low cross into the box where Williams mis-kicked completely when he seemed certain to score.
County went close early in the second half but Anthony Elding missed Griffin's cross from close range.
Both sides made substitutions just after the hour as they tried to gain an advantage but the game went through a scrappy stage.
McEvilly shot wide before he was replaced by Jamie Reed and when play switched to the other end, Ingham made his best save of the match by turning away a fierce drive from Poole.
Reed missed a great chance late on by shooting wide from Done's pinpoint cross and County rubbed salt into the home side's wounds right at the death.