With the score all-square heading into the final quarter, the Gills plundered two goals in the final 15 minutes to earn an upset at the Priestfield Stadium.
The home side went ahead in the ninth minute through Cody McDonald, who shot past Dons goalkeeper Ian McLoughlin after a smart Bradley Dack lay-off.
The visitors were level nine minutes before the break when Manchester City loanee Devante Cole found space in the box to finish superbly for his third goal since joining the club in January.
But two minutes later Dack broke into the box and smashed the ball home to make it 2-1.
Gillingham nearly added another when McDonald’s shot struck the post via McLoughlin before Ben Reeves equalised from the spot for the Dons after Gavin Hoyte had brought down Carl Baker.
The Gills were not to be denied though and Bradley Garmston’s low shot slipped through the hands of McLoughlin to make it 3-2 and the hosts sealed all three-points when John Marquis latched on to Dack’s ball and confidently struck home in the 81st minute.