Fleetwood's Sky Bet League One status was confirmed despite a 4-2 defeat at Bolton.
Stephen Crainey's visitors avoided relegation on goal difference ahead of Gillingham after a roller coaster game that finished with Wanderers' fourth successive victory.
Dion Charles, who ended a 14-game goal drought for club and country after 37 minutes, scored a remarkable goal after sliding in for an 86th-minute challenge.
The ball cannoned off a Fleetwood player and looped 45 yards into the net with Fleetwood keeper Alex Cairns wrong-footed.
Ten minutes earlier, Joe Garner's third goal in as many games via Danny Andrews' corner brought Town level at 2-2.
Fleetwood, who have been in the third tier since winning promotion in 2014, led through Barry Baggley's superb first Football League goal after 17 minutes.
Charles made it 1-1 for a Trotters side who finish their campaign with an eight-game unbeaten run.
Left-back Declan John's deflected shot put Ian Evatt's side in front before Garner's header looked to have earned the visitors a point.
Instead, Charles and substitute Jon Dadi Bodvarsson in added time completed Wanderers' win.