A last gasp Tom Eaves penalty sank Fleetwood Town at the Priestfield Stadium.
Town took a deserved lead through Paddy Madden in the first half but the Gills fought back in the second half through an Eaves double.
Fleetwood Town boss Uwe Rosler made four changes to the side that lost 2-1 to Blackburn Rovers last time out.
Devante Cole was not on the team sheet, Town's top scorer did not make the trip due to speculation surrounding his Fleetwood future.
New PNE loanee Kevin O'Connor made his debut at left-back with Conor McAleny, Ash Hunter and George Glendon in for Cole, Markus Schwabl, Wes Burns and Gethin Jones.
It was a strong and solid start by Fleetwood as the new-look front three of McAleny, Hunter and Madden linked-up well with Dempsey, Diagouraga and Glendon also developing a relationship behind them with some slick first-time football.
And Town got the goal their start deserved as they piled on the pressure. Hunter's set-piece from the right caused chaos in the Gillingham box, with a clearance eventually falling to Kyle Dempsey. The Priestfield Stadium holds happy memories for Dempsey after his last-gasp winner in 2017 kept Town's automatic promotion hopes alive but history did not repeat itself as his strike was deflected out for a corner.
And Fleetwood took the lead from that subsequent set-piece, Glendon whipped the ball into the mix, Madden's strike eventually fell to McAleny on the right and his goalbound strike was bundled home by Madden who was lurking at the back stick in the 13th minute.
Town asked serious questions of the Gills on set-pieces and Bolger should have done better as he rose above the pack to nod Glendon's corner from the right wide of the near post.
It was a tasty affair with a number of challenges flying in, the home crowd were not too happy when a 50/50 between Madden and O'Neill deep in Town's half resulted in just a Gills throw-in.
O'Neill was involved in numerous meaty challenges with McAleny unhappy with one of his attempts to stop Fleetwood's attacks and Hessenthaler went into the book for a challenge on O'Connor that left Town's new left-back needing treatment.
The Gills grew into the game as Fleetwood allowed them to keep possession though in un-dangerous positions.
The hosts won numerous set-pieces but Town handled everything they threw at them with Reilly forcing Neal into a save and Parker nearly sneaking in after out-foxing O'Connor but Bolger was on hand to mop up.
Martin too had an effort for the hosts but he chipped the ball straight at Neal when he perhaps should have slid in Eaves on the overlap on his left.
Hunter nearly snuck in late on in the first half but he could not quite angle the ball home after good pressing lead to another Town chance.
Gillingham came straight out of the blocks in the second half and bombarded Fleetwood.
That pressure told as Town buckled under their Achilles Heel of set-pieces as the giant Eaves flicked home a corner in the 53rd minute.
The Gills kept the heat on but Town with three shots blocked out in quick succession but that lead to a chance for Town.
Rosler's men are famed for their counter-attacking play and with the calibre of their forward line are always a threat with Madden racing out of his own half and feeding McAleny who should have fed his fellow forward back in but instead rifled the ball tamely past the left stick.
Town nearly succumbed at the back stick once again as Parker nearly snuck in but Town survived once again.
It was all Gillingham though at the start of the second 45 and they continued to pile on the pressure with Eaves seeing an effort deflected and Neal having to pull off a double save to thwart the forward as Rosler's men clung on.
The German made an attacking double substitution with 13 minutes to go as he refreshed the forward line by sending on Burns and Hiwula for McAleny and Hunter.
Burns nearly gave Town the lead as he pounced on a delightful Madden chip but Holy somehow tipped away his header. Town threatened from the corner as Grant slipped the ball to Coyle at the top of the box but he curled the ball way over.
And Gillingham finally got their winner at the death as Burns felled Reilly in the box and Eaves tucked away the subsequent spot-kick in the 89th minute.
Burns nearly popped up with a leveller as Town tried in vain to find a way back but he just could not turn home Hiwula's ball in the six-yard box.
Fleetwood: Neal, Coyle, Bolger, Eastham, O'Connor, Diagouraga, Glendon (Grant, 68), Dempsey, Hunter (Burns, 77), Madden, McAleny (Hiwula, 77). Subs not used: Cairns, Hiwula, Burns, Rodgers, Jones, Schwabl.
Gillingham: Holy, O'Neill, Garmston, Ehmer, Zakuan (Ogilvie, 60), Hessenthaler, Eaves, Martin, Parker (List, 82), Reilly. Byrne. Subs not used: Nelson, Lacey, Wilkinson, Nash Moussa.
Referee: Brett Huxtable.