Chesterfield 2 Wrexham 1
Goals from Peter Leven and Jack Lester gave the home side a commanding half-time lead but the Welsh club showed great spirit in the last 20 minutes and almost snatched an unlikely draw.
A 68th minute header from Steve Evans saw Chesterfield lose their composure and Michael Proctor wasted two excellent chances to earn his team a point.
But the Spireites will wonder how they managed to end a game they had controlled for so long in a state of near panic.
They should have killed the visitors off, but wasteful finishing almost proved their undoing and it needed two vital saves from Barry Roche in the last six minutes to prevent two points slipping away.
At least Wrexham can take some heart from the way they finished the game although they will remain in deep trouble as long as they give soft goals away.
The opening goal from Leven was a clever lob from 35 yards, but it was all down to a poor clearance from goalkeeper Anthony Williams who could not prevent the midfielder's spectacular effort crossing the line.
That was the cue for Chesterfield to take the game by the scruff of the neck and both Adam Rooney and Jamie Ward could have added further goals before Lester tucked away his 17th of the season four minutes before half-time.
Leven was again involved, this time knocking the ball down on the edge of the box and Lester skilfully placed a right-foot shot into the bottom left-hand corner.
The striker has now scored more goals than Wrexham's entire team and he was close to adding another when his diving header crashed just over the bar in the 59th minute.
Wrexham had hardly threatened but when Evans headed in Levi Mackin's corner the whole game changed.
Suddenly Chesterfield were giving the ball away needlessly and Proctor broke free in the 84th minute only to see Roche tip his low shot behind.
The striker should have equalised two minutes later when he got through on the right but he drove his effort straight at Roche and, when Neil Roberts had a back-heel cleared off the line, Wrexham knew it was not gong to be their day.