Cody McDonald and Bradley Dack gave the Gills a two-goal advantage within the opening 32 minutes, but were stunned as Kieron Morris and Milan Lalkovic brought the game level by both scoring in the space of two minutes.
Jason Demetriou then rounded off the goalscoring drama in the final minute of play by netting the winner to take his side to the top of the table.
Meanwhile, Burton Albion pushed closer to the top spot and overtook Gillingham to go second thanks to a 1-0 away victory against Oldham Athletic, with Abdenasser El Khayati's first-half goal enough to defeat the Latics.
Bury produced a convincing attacking display and moved up to fourth with a 4-3 home win over Blackpool, as a Danny Rose brace and goals from Chris Hussey and Tom Soares cancelled out finishes from Mark Cullen, Clark Robertson and Jack Redshaw.
Coventry City came from behind to beat Peterborough United, with a second-half goal from Romain Vincelot and late Adam Armstrong brace cancelling out finishes from Jermaine Anderson and Erhun Oztumer to secure a 3-2 win.
Results in full: Bury 4-3 Blackpool, Crewe Alexandra 1-0 Sheffield United, Doncaster Rovers 2-0 Colchester United, Millwall 0-0 Bradford City, Oldham Athletic 0-1 Burton Albion, Port Vale 2-0 Shrewsbury Town, Scunthorpe United 2-0 Barnsley, Southend United 2-2 Rochdale, Walsall 3-2 Gillingham, Wigan Athletic 1-0 Swindon Town, Fleetwood Town 0-1 Chesterfield, Coventry City 3-2 Peterborough United