Two freak goals kept this West County derby level at half time, the first coming after four minutes when a long ball forward caught out Rovers goalkeeper Steve Phillips and defender Byron Anthony, who collided when challenged by Town striker Billy Paynter.
Cox pounced on the loose ball to slot in from 20-yards as the Rovers players lay injured.
Anthony’s injury looked serious and after a six-minute delay he was stretchered off. However, it later transpired to be less serious than first feared.
Rovers came into the game and levelled after 21 minutes with a fortunate goal when Kevin Amankwaah’s clearance rebounded off Darryl Duffy’s foot to skid beyond goalkeeper Phil Smith, who was left with no chance.
The second half was a more even affair but Swindon left it late to score against the run of the play after 81 minutes when Amankwaah’s poor cross was not cleared and Cox struck in from 16 yards for his 30th goal of the season.