Defeat to Aldershot in midweek forced the Robins to wait for promotion and they looked set to extend the agony when Danny Kedwell and Whelpdale struck in the first half at Priestfield as the Gills looked to retain their faint play-off hopes.
But Torquay's loss at AFC Wimbledon meant League One football next season for Swindon, despite Whelpdale securing victory from the spot after Alan McCormack reduced the arrears.
Alan Connell wasted a great chance to put Swindon ahead when he fired straight at Gills goalkeeper Paulo Gazzaniga before Kedwell's looping header from Charlie Lee's long throw put the hosts ahead on the 26th minute.
After Connell saw a second effort saved by Gazzaniga, manager Paolo Di Canio responded by hauling off his striker in the 36th minutes before Gillingham midfielder Lewis Montrose hit the bar on the stroke of half-time.
The Gills doubled their advantage in the 52nd minute as Whelpdale chipped over Phil Smith. McCormack pulled one back for Swindon from 20 yards only for Whelpdale to wrap up the win with a late penalty after Jonathan Smith fouled Curtis Weston.
Any reproduction, publication or redistribution of this material without the written agreement of 365 Media Group is strictly forbidden.