Paolo di Canio's Swindon sealed promotion from League Two despite losing at Gillingham.
Danny Kedwell's looping header over keeper Phil Smith put the Gills ahead and they doubled their lead through Chris Whelpdale's cross-shot.
Alan McCormack drilled home to give Swindon hope, before Whelpdale made it 3-1 from the penalty spot.
But with Torquay and Crawley dropping points, the Robins secured a return to League One at the first time of asking.
Di Canio made eight changes to the side that lost to Aldershot on Tuesday, with four players dropped for their involvement in
last weekend's well-documented night out.
One of those punished was in-form keeper Wes Foderingham and it was his replacement Smith who was at fault for the first goal.
Charlie Lee's long throw found Kedwell, and the striker nodded the ball over Smith, who had found himself stranded off his line.
Swindon looked in disarray and boos from the Town fans rang out when top scorer Alan Connell, playing as a lone striker, was brought off after just 39 minutes to be replaced by Ronan Murray.
Did you know?
Swindon had not lost back-to-back league games since August
The Gills grew in confidence and shortly before half-time they missed two opportunities to increase their lead - Lewis Montrose's stunning strike hit the crossbar while Whelpdale saw his header go wide.
The hosts started the second half in a similar fashion and Whelpdale's delicate chip gave them the second goal they deserved.
Swindon rarely tested Gills keeper Paulo Gazzaniga but McCormack's low drive gave the visitors a lifeline.
However, their defeat was confirmed when Whelpdale struck from the spot, after Curtis Weston was brought down by Jonathan Smith.
But with results from other grounds going their way, Di Canio was able to hold his red and white scarf aloft in front of 1,400 travelling fans and celebrate Swindon's promotion in his first season in charge at the County Ground.
Gillingham also strengthened their position in the promotion push and now sit just four points off Crewe, who currently occupy the final play-off place.
VIEWS FROM THE DRESSING ROOM
Swindon Town manager Paolo di Canio told BBC Points West:
"I'm never going to say why, but a month ago I nearly resigned my contract. I have to tell people now that we are up.
"I didn't do this because I promised my fans at the beginning of the season that we would go up.
"If I went now, this team - without Paolo di Canio - are capable of losing 13 games in a row. They've shown that in the last two games.
"I've told them already in the dressing room that we have to change the direction because if you become arrogant like we have, then we are average."
- 28 Gazzaniga
- 03 Frampton Booked
- 12 Martin
- 16 Fish
- 18 Jackman Booked
- 22 Essam Booked
- 04 C Lee (Spiller - 71' )
- 07 Whelpdale
- 19 Montrose
- 09 Kedwell Booked (Weston - 82' )
- 33 Kuffour (Vine - 73' )
- 05 King
- 10 Weston
- 17 Spiller
- 11 Oli
- 23 Vine
- 26 Smith
- 02 McEveley
- 04 Flint
- 07 Caddis
- 08 Ferry
- 10 Ritchie
- 12 McCormack
- 13 Risser (Smith - 52' )
- 14 Bostock
- 22 Holmes (Gabilondo - 72' )
- 17 Connell (Murray - 36' )
- 18 Scott
- 15 Thompson
- 21 Gabilondo
- 24 Smith
- 34 Murray