Sam Morsy's 25-yard strike put the hosts ahead, but Aiden O'Brien headed in Shane Ferguson's cross to level.
Lee Gregory scored the winner from 10 yards early in the second half.
Keeper Jordan Archer denied Morsy and Byron Harrison to seal victory as Millwall moved into the play-off places, and left the Spireites two points above the relegation zone.
Millwall manager Neil Harris told BBC Radio London:
Media playback is not supported on this device
"For us as a group to break into the top six in January is a fantastic achievement. It gives us something to grow from.
"It's terrific to come to Chesterfield away from home in January and show character and resilience to come back and win.
"I'm really delighted with my players.
"We took care of the ball, and if we do that we've got players who can hurt the opposition."
Millwall kept up their League One promotion push with victory at struggling Chesterfield.