Gillingham secured a valuable victory at Priestfield against top-of-the-table Swindon.
Danny Kedwell put the Gills ahead midway through the first half and early in the second Chris Whelpdale doubled the advantage.
That lead was halved when Alan McCormack unleashed a powerful effort past Gills keeper Paulo Gazzaniga late on.
Whelpdale eventually converted an injury-time penalty to seal a precious three points for the Gills, as they hang onto hopes of a play-off place in League 2.
Gillingham had to soak up a fair amount of pressure early on against a Swindon team looking to wrap up their promotion to League 1.
Oliver Risser tried to catch Gazzaniga out early on but the Argentine was alert and caught the attempted lob.
Chances at the other end were rare and Matt Fish’s shot almost hit the watching police officers on the top of the control tower. Later in the half he found his range, testing keeper Phil Smith with a shot after a good run forward.
That effort from Fish came shortly after the Gills had taken the lead. Charlie Lee – back in the starting eleven after recovering from injury – hurled in a long throw and the flick from Kedwell looped over the keeper and into the net on 26 minutes.
Gazzaniga got down well to deny Alan Connell, as Swindon searched for an immediate reply, but Gillingham midfielder Lewis Montrose smashed an audacious 20-yard effort against the bar. It was still rattling as Chris Whelpdale headed narrowly wide moments later.
Lee Holmes put a good chance wide for Swindon early in the second half after Danny Jackman had conceded possession.
With seven second half minutes gone the Gills doubled the lead as Montrose and Whelpdale showed sheer determination to keep alive an attack. When the ball fell to the latter he guided the ball past the keeper with a great finish.
Gazzaniga got down well to save a powerful Ritchie effort just before the hour mark while at the other end Jo Kuffour put Whelpdale through on goal but the shot that followed went narrowly wide.
After a lull in the action, the game burst back to life when Swindon’s McCormack burst through the middle and drove a low and powerful shot past Gazzaniga to make it 2-1 with just less than 10 minutes left.
Whelpdale forced Smith into making a good save in the last minute but for the final minutes the Gills had to hang on, with five additional minutes added.
Nerves were calmed when Curtis Weston was fouled in the box and Whelpdale tucked away the resulting spot-kick. It was the last kick of the game as the Gills got the win they craved, while Swindon were promoted despite the defeat.
Gillingham: Gazzaniga, Martin, Fish, Frampton, Essam, Montrose, Whelpdale, Lee (Spiller 71mins), Jackman, Kuffour (Vine 74mins), Kedwell (Weston 83mins). Subs: King, Oli.
Swindon: P Smith, Caddis, McCormack, Flint, McEveley, Ritchie, Ferry, Risser (J Smith 53mins), Bostock, Holmes (Gabilondo 73mins), Connell (Murray 37mins). Subs: Scott, N Thompson.
Don't miss out, subscribe today. Keep up to date with our newsletters.
A guide for your future. For year 11 students in Kent and Medway. Click here for the e-edition.
Education, Training & Childcare is a special supplement published by KM Media Group four times a year. Click here for latest e-edition.
Get the latest food and drink news, recipes from some of the nation's top chefs plus updates from Kent's vineyards and breweries.
Search in your local area to find your perfect partner in Kent, with FreshStart Dating! PLUS, register for free!.
Find out what's going on in the garden, with Kent expert Lucy Hewett's weekly update.
Buy pictures that you've seen in a KM newspaper, or send in a picture and we will place it on our photo sales website so that you can purchase a super, unique gift.