The former Newcastle bad-boy outmuscled his man before shooting past a diving Frankie Fielding with just three minutes left on the clock for his first Swindon league goal.
Nicky Ajose, their loan signing from Peterborough, had earlier scored either side of goals from Aden Flint and Jay Emmanuel-Thomas to keep the pressure on Robins head coach Sean O'Driscoll.
In a frenetic first half, City opened the scoring after eight minutes when former Swindon defender Flint headed home from a corner.
But with City looking nervous at the back, the lead lasted just ten minutes with Ajose angling a neat strike past Fielding after thundering into the box.
The game was flowing from end to end and former Arsenal frontman Emmanuel-Thomas put his side ahead for the second time with 35 minutes gone on the clock. He latched on to a short ball before cutting inside and driving a shot into the net from the edge of the area.
Three minutes before the interval the scores were level. Good work from Ranger was rewarded when Ajose tapped home from one yard out to grab his second of the day.
Ranger's goal in the dying moments meant City are now without a win in eight games while the Robins have bragging rights over their local rivals.