Callum Reilly scored a stoppage-time winner against his former club as AFC Wimbledon ended Gillingham's 15-match unbeaten run in League One with a 2-1 victory at Priestfield.
Winless in seven games prior to kick-off, the Dons started brightly and saw Anthony Hartigan test Gillingham goalkeeper Jack Bonham with a free-kick after just 55 seconds.
Gills captain Max Ehmer came to Bonham's rescue after 14 minutes when he acrobatically cleared Joe Pigott's goal-bound lob off the line.
The visitors deservedly took the lead four minutes after the break when Pigott fired into an empty net after Bonham's parry from Kwesi Appiah's header fell to him six yards out.
On-loan Cardiff goalkeeper Joe Day maintained the Dons' lead when he produced a spectacular fingertip save to keep out John Akinde's header.
However, Day was helpless to prevent Gills substitute Regan Charles-Cook from heading home an equaliser three minutes from time.
That looked to have salvaged Gillingham's unbeaten run but there was still time for Reilly to dramatically earn the Dons a precious victory.
The midfielder, who left Gillingham for free last summer, fired past Bonham in the first minute of stoppage time to snatch all three points for the visitors.