Rory Fallon's stoppage-time header ended high-flying Colchester's 12-game unbeaten run.
The New Zealand striker stooped at the near post to meet sub Hameur Bouazza's cross two minutes into injury time. It was a just reward for the home side who had been the better team throughout against fourth-placed Colchester.
Swindon's best opportunity of the first half came when 19-year-old striker Ashan Holgate met a near-post corner from Jack Smith but U's keeper Aidan Davison somehow managed to claw the ball away.
The young attacker seemed to be Swindon's best source for goals in the first half and again went close on the half-hour mark.
Ricky Shakes delivered an inviting cross along the six-yard box but both Holgate and Fallon narrowly failed to connect.
Colchester's only two real efforts of the half were Greg Halford's header and a Richard Garcia shot which was well-saved by Rhys Evans.
The second half continued in a similar vein to the first period with Colchester having all the early possession before Swindon came back in to the game with 30 minutes left.
Evans' fantastic save from a Mark Yeates free-kick seemed to galvanise the home side to go on and get all three points.
A great run on 69 minutes by Aaron Brown finished with the ball finding its way to the feet of substitute Mike Pook but the midfielder fired just over from 20 yards.
Bouazza came off the bench to replace Holgate with just ten minutes left and his pace troubled the tiring Colchester back four.
The Frenchman, on loan from Watford, was unlucky when a left-footed shot deceived Aidan Davison who dived to his left but somehow produced a save with his trailing right arm.
The substitute soon had his revenge though when he out-paced John White down the left-hand side and crossed for Fallon to send the County Ground into delirium.