The visitors had led by one goal at half time and further goals at the start and end of the second half confirmed the Gills first League win at the County Ground since March 1982.
Swindon made three changes with Yaser Kasim, Harry Toffolo and John Swift starting in place of Louis Thompson, Jack Stephens and Ben Gladwin.
There was one minute's applause before the game started in memory of ex-Town manager Dave Mackay who died on Monday 2nd March.
Gillingham kicked off playing towards the Town End and earned a corner in the 5th minute after Nathan Byrne just failed to keep the ball in play but the cross was flicked across goal by a Gills player and ran out to safety on the wing.
Town’s first serious attack in the 10th minute saw Byrne pass to Tomfool who was overlapping on the left side of the box when a shot may have been a better option and the ball ran harmlessly out for a goal kick. Byrne was involved soon afterwards when he crossed from the right wing into the box for Michael Smith who chose to backheel the ball towards Williams instead of shooting and a defender cleared.
Massimo Luongo was caught in possession near the halfway line in the 15th minute and the ball was passed to Josh Pritchard who advanced into the penalty area before firing left of the upright under pressure from two Town defenders.
Town had a corner in the 18th minute after Smith’s cross had been deflected behind and that led to John Swift firing a shot on goal which struck a defender and the ball was cleared.
A long ball downfield from Foderingham led to a corner in the 23rd minute and although that was initially cleared, the ball spilled to Kasim but his shot went wide of goal and eventually Town were penalised for offside in the follow up.;
Michael Smith did well to send a deep cross from the right wing across goal where it was headed just wide of goal by Andy Williams in the 28th minute.
Disaster struck for Town in the 29th minute when Cody McDonald scored with a cheeky first time backheel after the ball had been crossed from the Gills left wing by Loft.
There was a minor flashpoint when Turnbull was penalised for fouling a Gills player in the 35th minute but the referee decided a long telling off was enough for Turnbull with Nathan Thompson invited to listen in.
Doug Loft was shown a yellow card in the 41st minute for fouling Kasim off the ball although the referee did play a good advantage to allow Town to attack.
Town had a free kick some 25 yards from goal for a foul but Kasim’s effort went right across goal with no Town player able to get a touch and the ball went out for a goal kick.
Two minutes of added time were played with neither side getting any chances on goal and the half ended with the Gills ahead having made the best of their chance in front of goal.
The second half started abysmally for Town when they gifted possession to the Gills straightaway and the ball was knocked down the wing before it was crossed by Dack to Jake Hessenthaler who headed home with just 20 seconds on the clock.
Josh Pritchard was cautioned for a foul near the halfway line in the 48th minute.
Nathan Byrne had a shot on goal in the 52nd minute which went wide and then Jon Obika replaced Michael Smith as Mark Cooper looked to try and get something from the match.
Andy Williams was presented with a chance in the 54th minute but his hurried effort was mishit and the ball looped over the crossbar.
Swindon were struggling to get any momentum with the Gills looking good value for their two goal lead and Rossi-Branco let his frustration show and was shown a yellow card for a foul in the 59th minute.
Jermaine Hylton replaced Andy Williams in the 61st minute while Town were waiting to take a free kick for a foul on Byrne which saw John Egan cautioned.
Nathan Thompson had to receive treatment after being fouled by Dack who was cautioned along with Foderingham for getting involved in the aftermath in the 63rd minute.
Hylton earned a corner for Town in the 67th minute which led to Obika heading over with the goalkeeper Stuart Nelson beaten.
A good move started by Luongo set up Obika but he miskicked and the ball went out harmlessly for a goal kick in the 70th minute.
Town gained a corner in the 72nd minute thanks to Luongo’s deflected shot but the resulting corner was cleared.
Ben Gladwin replaced Rossi-Branco in the 74th minute with Town trying a new formation including two players at the back.
John Marquis was replaced in the 78th minute by Luke Norris with Gillingham firmly in control and their confidence was demonstrated by Doug Loft who sent a superb rising shot only just over the Town crossbar in the 81st minute. Loft repeated his efforts within two minutes firing in another powerful shot which Foderingham did well to push over at the expense of a corner.
Ben Gladwin was unfortunate to be denied by the upright in the 86th minute after firing in a shot on the turn but the ball cannoned back off the post.
Town’s night got even worse in the 88th minute when a long ball over the defence reached Cody McDonald who scored from the edge of the box with a flicked effort to guide the ball over Foderingham who was desperately trying to get back on his line.
Town continued to push forward in the five minutes of added time but the visiting defence stood firm and so Gillingham won a League game for the first time at the County Ground since March 1982.