Connor Ogilvie hit Gillingham's winner as they edged out MK Dons 3-2 in a thrilling game at Priestfield.
Will Grigg opened the scoring for the visitors after just four minutes when he curled into the bottom corner to end a Dons move that comprised 55 passes.
Jordan Graham drew the hosts level from the penalty spot on 28 minutes after Warren O'Hora had blocked Stuart O'Keefe's header with his arm.
Gills striker Vadaine Oliver capitalised on another Dons mistake - this time a poor defensive header from Andrew Surman - to put the Kent side in front a minute before the break.
O'Hora made amends when he met Ethan Laird's low cross to make it 2-2 six minutes into first-half stoppage time.
Only a stunning fingertip save from Dons goalkeeper Andrew Fisher prevented Olly Lee from putting Gills ahead with his 25-yard attempt.
But Fisher was helpless to keep out Ogilvie's powerful half-volley that won Gillingham the game 16 minutes from time after the visitors' defence had failed to clear Ryan Jackson's throw.