Flint opened the scoring in the 34th minute, heading in from former Gillingham player Luke Freeman’s corner.
Smith appeared to get the final touch on the ball before it crossed the goalline, but there was little doubt when he doubled City’s advantage a minute before the break.
After good play by Derrick Williams, the Robins broke down the left with Greg Cunningham and from his cross, Smith tapped in from close range.
Cody McDonald’s eighth goal of the season two minutes after half-time briefly brought the Gills back into contention.
However, local boy Wagstaff secured City’s sixth away league victory of the season shortly before the hour-mark with a brilliant curling effort from the edge of the penalty area.
Jay Emmanuel-Thomas also had an effort ruled out for offside and forced Gills goalkeeper Stuart Nelson into a good save from a powerful drive.