Substitute Gareth Edds scored a dramatic late winner that could go a long way to keeping MK Dons in League One.
Edds buried a low right-foot shot with only his second touch in the 86th minute just two minutes after coming on.
But the real hero for the visitors was keeper Matt Baker who kept his team in the game after the break.
Clive Platt had given the Dons a 12th minute lead but it was all Chesterfield after Colin Larkin equalised in the 50th minute.
Chesterfield created chance after chance but they could not beat Baker again and Edds secured a fourth straight win that gives them hope of avoiding relegation.
With two games to go, Danny Wilson's team can control their own destiny but they lived dangerously at times against a Chesterfield side who banished their lingering memories of going down in midweek.
In the first half Chesterfield played like a team with nothing at stake and Platt put the visitors in command with a close-range header from a short corner.
They could have had another when Platt put Gary Smith in but Barry Roche rushed off his line to save and it was a different story in the second half.
Chesterfield started to pass the ball and when Mark Allott headed down Jamie O'Hara's left-wing cross, Larkin beat Baker from inside the six-yard box.
Substitute Izale McLeod forced Roche into a reaction save with a snap-shot on the turn but Baker was the busier of the two keepers as he pulled off a string of outstanding saves.
He dived at the feet of Derek Niven when the midfielder had been put clear by Larkin and then blocked a Niven header two minutes later before keeping out Allott's follow up with his legs.
The importance of Baker's heroics became clear four minutes from the end when Edds scored what cold be a priceless goal with only his second touch.
Platt laid a pass from Scott Taylor invitingly to Edds who placed a low right-foot shot from the edge of the area past the outstretched right-hand of Roche and into the bottom corner.