Three goals in the second half won Chesterfield the League Two title and denied Gillingham a play-off place.
Danny Whitaker put the hosts in front when he rounded Gills goalkeeper Alan Julian and finished from a tight angle.
Gillingham's top goalscorer Cody McDonald equalised when he collected a through ball from Adebayo Akinfenwa and calmly nudged the ball past Tommy Lee.
But Jack Lester flicked in from Scott Griffiths' pass before Deane Smalley wrapped up the victory with a tap-in.
Chesterfield only needed a point for the championship, while Gillingham were hoping Torquay or Stevenage would slip up to move into the play-offs.
The home side started brightly and dominated possession in the opening stages but could not create many chances apart from a long range effort from Whitaker, which he dragged wide from 35 yards.
The visitors fought their way back into the game as Mark Bentley and McDonald shot over before McDonald was denied when clean through by Lee.
Whitaker's goal early in the second half started the title celebrations, although McDonald's leveller gave Gills some hope.
But Lester made it 2-1 before Smalley settled the Chesterfield nerves when he finished from close-range after a storming run from Griffiths.
Chesterfield boss John Sheridan told BBC Radio Sheffield:
"It's been a long time coming, we've been in a very healthy position for a long time and I'm pleased, proud of the players.
"I think we play a type of football that would attract fans, we've got results and the winning mentality.
"I honestly wasn't bothered about Bury, I was trying to concentrate on us and I knew a point would have been enough. "
Gillingham boss Andy Hessenthaler told BBC Radio Kent:
"I can't be too critical of the lads. At half time things were going how we planned them, but in the second half we conceded but then gave ourselves a lifeline.
"There were no fingers pointing today, it's about 46 games. Up until the 76th minute we had something and we were there, but ultimately it wasn't to be.
"It was over the season, not just about today. It's about consistency. The early part of the season was disjointed, half the squad was in the stand."