Trinidad & Tobago international Brent Sancho scored his first goal in English football to hand Gillingham victory.
It came four minutes from full time at Priestfield and Sancho's header was good enough to see off Chesterfield, who would have felt hard done by not to have earned at least a point.
The first incident of a note in the game came when Gareth Davies brought down Matt Jarvis on four minutes and Darren Byfield curled the resulting free-kick straight into Barry Roche's arms.
In the ninth minute Chesterfield conjured up their first attempt, although Derek Niven would have wanted to forget it in a hurry as he sliced well wide.
Gillingham nearly drew first blood on the 25 minute mark when Tom Williams launched a long throw into the box, Andrew Crofts rose highest and his thumping header was expertly tipped over by Roche.
Roche was called upon again to palm away Sancho's header following a corner by Williams and the best chance of the half then arrived on the half hour mark.
Neil Harris spotted Andy Hessenthaler's run and the veteran midfielder took it in his stride before waltzing past Reuben Hazell only for Roche to get his hands to the shot.
Colin Larkin then looked threatening for Chesterfield in the box but Leon Johnson's challenge halted him in his tracks and the sides went in level at the break.
On the hour mark Paul Hall nut-megged Williams but couldn't pick out a cross from a dangerous position and he later shot straight at Jason Brown.
With a goalless draw looking the most likely outcome, Sancho glanced in a header from Steven Hislop's inch-perfect right-wing cross to settle the match in favour of the Gills.