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
Live Text Commentary
Full Time The referee ends the match.90:00 +5:59 Goal scored
Goal! - Chris Whelpdale - Gillingham 3 - 1 Swindon Penalty taken right-footed by Chris Whelpdale and scored. Gillingham 3-1 Swindon.90:00 +5:06
Curtis Weston fouled by Jonathan Smith, the ref awards a Penalty.90:00 +4:41
Rowan Vine decides to take a short corner.90:00 +1:49
The referee blows for offside. Phil Smith takes the indirect free kick.90:00 +0:47
Free kick awarded for a foul by Joe Martin on Matt Ritchie. Matt Ritchie crosses the ball from the free kick left-footed from right wing, Danny Jackman makes a clearance.89:09
Inswinging corner taken by Danny Spiller from the left by-line.88:52
Chris Whelpdale takes a shot. Save by Phil Smith.86:15
Free kick crossed right-footed by Paul Caddis from left channel.86:15 Booking
Booking The referee cautions Connor Essam for unsporting behaviour.86:00
Free kick awarded for a foul by Connor Essam on Jay McEveley.82:53
Ronan Murray has an effort at goal from just outside the box which goes wide of the left-hand post.81:28 Substitution
Substitution Curtis Weston is brought on as a substitute for Danny Kedwell.81:09
The referee blows for offside against Rowan Vine. Direct free kick taken by Alan McCormack.80:10
Assist on the goal came from Jonathan Smith.80:10 Goal scored
Goal! - Alan McCormack - Gillingham 2 - 1 Swindon Alan McCormack scores a goal from just outside the area to the bottom right corner of the goal. Gillingham 2-1 Swindon.77:38
Simon Ferry fouled by Rowan Vine, the ref awards a free kick. Alan McCormack restarts play with the free kick.75:10
Foul by Jay McEveley on Rowan Vine, free kick awarded. Free kick crossed right-footed by Danny Spiller, clearance made by Alan McCormack.72:46 Substitution
Substitution Rowan Vine joins the action as a substitute, replacing Jo Kuffour.71:40 Substitution
Substitution Lee Holmes leaves the field to be replaced by Lander Gabilondo.
Indirect free kick taken by Paulo Gazzaniga.69:58 Substitution
Substitution Danny Spiller comes on in place of Charlie Lee.69:58
Lee Holmes is caught offside.69:11
Charlie Lee challenges Alan McCormack unfairly and gives away a free kick. Free kick taken by Alan McCormack.68:37
Corner taken by Lee Holmes, Chris Whelpdale manages to make a clearance.66:48
Ronan Murray produces a drilled right-footed shot from 20 yards. Blocked by Andy Frampton.62:40
Effort from just outside the area by Lewis Montrose goes over the bar.59:22
Short corner taken by Matt Ritchie.57:49
Effort from just inside the area by Chris Whelpdale strikes the post.56:58
Inswinging corner taken by Matt Ritchie from the right by-line.56:43
Matt Ritchie has a drilled shot. Save by Paulo Gazzaniga.55:53
Paul Caddis restarts play with the free kick.55:53 Booking
Booking Danny Jackman goes into the book.55:34
Danny Jackman concedes a free kick for a foul on John Bostock.54:31
Free kick awarded for a foul by Joe Martin on Matt Ritchie. Paul Caddis takes the direct free kick.52:44
Free kick awarded for a foul by Chris Whelpdale on Simon Ferry. Free kick taken by Matt Ritchie.51:59 Substitution
Substitution Jonathan Smith replaces Oliver Risser.51:05 Goal scored
Goal! - Chris Whelpdale - Gillingham 2 - 0 Swindon Chris Whelpdale finds the back of the net with a goal from outside the area to the top right corner of the goal. Gillingham 2-0 Swindon.49:23
Danny Kedwell is flagged offside by the assistant referee. Free kick taken by Phil Smith.47:28
Lee Holmes has an effort at goal from just outside the box which goes wide of the right-hand upright.45:01
The referee gets the second half underway.45:00 +2:27 Half time
Half Time It is the end of the first-half.45:00 +1:58
Lewis Montrose challenges Simon Ferry unfairly and gives away a free kick. Free kick taken by Alan McCormack.45:00 +0:38
John Bostock concedes a free kick for a foul on Connor Essam. Matt Fish takes the free kick.44:24
Headed effort from deep inside the area by Chris Whelpdale misses to the right of the target.44:09
Lewis Montrose takes a shot.41:40
Matt Fish has a drilled shot. Save by Phil Smith.41:14
Danny Kedwell gives away a free kick for an unfair challenge on Alan McCormack. Direct free kick taken by Paul Caddis.39:04
Free kick awarded for a foul by Alan McCormack on Jo Kuffour. The free kick is delivered left-footed by Danny Jackman from right channel.36:50
Corner taken left-footed by Matt Ritchie to the near post, clearance by Lewis Montrose.35:44 Substitution
Substitution Ronan Murray replaces Alan Connell.34:22
Alan Connell challenges Danny Kedwell unfairly and gives away a free kick. Paulo Gazzaniga takes the direct free kick.33:54
Jay McEveley restarts play with the free kick.33:54 Booking
Booking Danny Kedwell goes into the referee's book for unsporting behaviour.33:17
Free kick awarded for an unfair challenge on Jay McEveley by Danny Kedwell.30:09
Matt Ritchie takes a inswinging corner from the right by-line played to the near post, Connor Essam makes a clearance.29:41
Free kick awarded for a foul by Charlie Lee on Jay McEveley. Jay McEveley takes the indirect free kick.28:58
Unfair challenge on Joe Martin by Matt Ritchie results in a free kick. Paulo Gazzaniga takes the free kick.28:09
Shot by Alan Connell. Paulo Gazzaniga makes a save.25:18
Charlie Lee provided the assist for the goal.25:18 Goal scored
Goal! - Danny Kedwell - Gillingham 1 - 0 Swindon Danny Kedwell scores a headed goal from deep inside the penalty box. Gillingham 1-0 Swindon.24:28
Oliver Risser challenges Lewis Montrose unfairly and gives away a free kick. Direct free kick taken by Danny Jackman.19:14
Simon Ferry fouled by Connor Essam, the ref awards a free kick. Alan McCormack takes the direct free kick.17:10
Shot by Alan Connell. Paulo Gazzaniga makes a comfortable save.15:42
Shot from 25 yards by John Bostock. Paulo Gazzaniga makes a save.14:54
Shot on goal by Matt Ritchie from just inside the area clears the crossbar.11:01
John Bostock takes a shot from long distance which goes wide of the right-hand upright.10:22
Free kick taken by Paul Caddis.10:22 Booking
Booking Andy Frampton receives a caution for unsporting behaviour.9:48
Andy Frampton is penalised for a handball.8:54
Matt Fish has a shot on goal from outside the area which misses left.7:15
Lee Holmes takes a short corner.6:20
Lewis Montrose concedes a free kick for a foul on John Bostock. Free kick taken by Alan McCormack.0:59
Shot by Oliver Risser. Save by Paulo Gazzaniga.0:00
The game kicks-off.
Live data and text provided by our data suppliers