A stunning Lewis Macari strike earned us victory in our 5,000th EFL match.
The substitute found the top corner with a sweet strike in the second half after the Gills had cancelled out Macaulay Langstaff's opener.
And that proved to be the difference on a historic day for the club.
After both missed the Nottinghamshire derby through injury, Luke Williams welcomed key men Kyle Cameron and Jodi Jones back into his starting XI.
John Bostock wasn’t fit to play, though, and both Sam Austin and Dan Crowley dropped to the bench.
That meant our midfield consisted of Matt Palmer and Jim O’Brien behind the more attack-minded Aaron Nemane and David McGoldrick.
Out wide, Jones and Tobi Adebayo looked to supply ammunition for Langstaff, while Sam Slocombe was protected by a back three of Cameron, Aden Baldwin and Richard Brindley.
But within 16 minutes Williams had to shuffle his pack at the back as Brindley joined the injury list, going down off the ball and being replaced by league debutant Macari.
We’d made a largely controlled start to the game but the Gills had claimed the first two opportunities before Brindley’s departure, Max Ehmer heading the ball over from a corner shortly before Macauley Bonne couldn’t keep his volley down after meeting a cross from the left.
Our response came from McGoldrick who, shortly after heading a half-chance over the bar, nearly took goalkeeper Jake Turner by surprise with a 30-yard shot on the turn. Turner managed to parry the ball to safety.
A minute later, Jones skinned his man down the left and saw his looping cross almost turned home by a defender as our pressure continued to mount.
But we had to remain diligent at the other end, as proved by Baldwin when he made a brilliant sliding challenge to halt a Gills attack down the left. His opponent’s boot inadvertently found Baldwin’s face on the follow-through but, after lengthy treatment, the defender was able to continue.
Another dangerous Jones cross then went unpunished, this time flying through a crowd of bodies and wide of the far post.
But we didn’t have to wait much longer to claim a deserved lead as Palmer worked the ball to Adeabyo down the right and watched on as the wing back delivered an excellent cross into the middle. Langstaff turned the ball goalwards and Turner couldn’t keep it out.
That proved to be the final action of the first half and, after emerging for the second unchanged, we had an excellent opportunity to double our lead when McGoldrick played the ball to Langstaff in the area. The forward, who had been hobbling for the minute leading up to the goal, managed to turn the ball on to his right foot but couldn’t get his shot away before being smothered by defenders.
Two minutes later, Palmer tracked back brilliantly to turn the ball behind after Bonne had failed to connect properly with his shot on the counter.
But the Gills kept up their pressure and had an equaliser on 52 minutes when we couldn’t get the ball clear deep inside our own territory and were unable to prevent Scott Malone from working the ball on to his left foot, and then into the bottom corner of Slocombe’s net.
We responded immediately through Jones, who controlled the ball inside the area and saw his piledriver pushed behind by Turner.
And the wide player was involved again moments later, seeing his brilliant low cross well dealt with by Turner with Langstaff ready to pounce inside the six-yard box.
Adebayo saw an attempted cross loop teasingly on to the roof of the net in what proved to be his final action as, shortly after Bonne had failed to turn home a close-range effort, he made way for Crowley.
Austin and Junior Morias were sent on 10 minutes later, Jones and Langstaff making way.
But it was our first substitute, Macari, who would grab the spotlight as the game entered its latter stages. Receiving a lay-off from Crowley 20 yards out, he arrowed a first-time shot into the top corner via the faintest of touches from Edwards.
With only 10 minutes of normal time remaining, the Gills piled on the pressure in pursuit of an equaliser – but we were getting opportunities on the break and saw a McGoldrick effort pushed away.
Max Clark sent a free-kick over from a dangerous position after O’Brien had committed a foul off the ball, moments before McGoldrick was denied again after magical interplay with Crowley – Edwards keeping his legs shut to stop his goalbound effort.
Six minutes were added on but, after Slocombe was struck by an object thrown from the crowd, an incident later investigated by Gillingham, the game rumbled on far beyond the allotted time.
Although the hosts’ pressure continued, we had a great chance to wrap it up when McGoldrick took control of the ball inside the penalty area. With the stretched Gills defence at sixes and sevens, he toyed with the goalkeeper and covering defender before eventually passing to Morias on his right, only for the assistant to raise his flag for offside.
But, after Slocombe had got an important hand to Jayden Clarke’s effort right at the death, Macari’s goal proved enough as we claimed a big three points.
STARTING XI: Slocombe; Cameron, Baldwin, Brindley (Macari 16'); Jones (Austin 71'), Adeabyo (Crowley 60'); Palmer, O'Brien, McGoldrick, Nemane; Langstaff (Morias 71')
UNUSED SUBS: Stone, Rawlinson, Tipton
BOOKINGS: O'Brien 84', Cameron 90+6', McGoldrick 90+6'
ATTENDANCE: 6,983 (820)