Late goals from Matt Ritchie and Jonathan Smith moved Swindon into the play-off places.
Gills' Luke Rooney went closest to breaking the deadlock in the first 80 minutes but his shot hit the inside of the post and rolled along the goalline.
With 10 minutes to go Ritchie put Paolo di Canio's Robins ahead with a stunning 30-yard strike.
Smith extended Swindon's winning run to three games in stoppage time with another shot from outside the area.
VIEWS FROM THE DRESSING ROOM
Swindon Town midfielder Matt Ritchie told BBC Wiltshire:
"I don't think it was a brilliant performance but we did exactly what we needed to do.
"I was due a goal - I haven't scored for five (games) so it was about time.
"The ball was a bit behind me and I didn't think I'd caught it great but I looked up and saw it swerve in."
Gillingham boss Andy Hessenthaler told BBC Radio Kent:
"It was very disappointing. The performance was terrific. I couldn't have asked for more from the boys.
"The decision making with the ball maybe wasn't up to where it should have been but I thought at times we played very well and created the best chances in the game.
"It was a wonderstrike from Ritchie. We knew if he comes inside he's got one hell of a shot, he did what he did. He's got that in abundance.
"I can't be too critical. All in all it was a good performance. There were more positives than negatives."