Orient super-sub Yohann Lasimant strode off the bench four minutes from time and headed a last-gasp winner as Russell Slade’s side ended a four-game league run without a win.
The 90th-minute strike earned the visitors maximum points and ensured they remain top of the table as they head to Wolves on Sunday for the final game of 2013.
But it looked as if the O’s might be heading towards defeat as Gillingham went in front after just two minutes through ex-Orient striker Bayo Akinfenwa and they held onto their lead until Marvin Bartley levelled for the visitors 20 minutes from time.
Orient manager Russell Slade was forced to shuffle the pack as goalkeeper Jake Larkins came in for his first league start of the season replacing the injured Jamie Jones.
With Lloyd James suspended, Bartley made a rare start in the centre of midfield, but Elliot Omozusi and Dean Cox both returned as Gary Sawyer and Lasimant dropped to the bench.
In a strange opening 45 minutes, Orient dominated for long spells, but just about everything that could have gone wrong Slade’s side did.
Gillingham were ahead inside two minutes, then Orient missed a great chance to level when Omozusi saw a penalty saved and to cap a miserable first half striker Shaun Batt limped off injured. It looked as if it wasn’t going to be the visitors’ day.
In fact, they could not have scripted a worse possible start when Gillingham, who began like a train, grabbed the lead on two minutes.
Larkins somehow clawed a Luke Hessenthaler header against a post and the ball was smuggled away for a corner. But from the resultant kick the giant Akinfenwa was left unmarked and he sent a looping header into the far top corner of the net.
It was just the sort of start that Larkins would have been dreading, but he made a smart stop low down from Hessenthaler shortly afterwards and that helped both the rookie keeper and his team-mates settle.
For the rest of the half Orient were more like a home side as they controlled long passages of play and knocked the ball around on a difficult surface. They could have levelled on 15 minutes when Kevin Lisbie headed a Cox free-kick just wide.
O’s had a penalty claim waved away by referee Fred Barber on 22 minutes when Batt appeared to have been pushed as he tried to attack Lisbie’s ball into the danger area.
However, the man in black had no hesitation pointing to the spot on the half-hour when Lisbie was felled by Leon Legge in the area.
O’s have proved less than proficient from the spot this season and it was Omozusi who stepped up only to see former O’s keeper Stuart Nelson dive to his right and keep out the kick.
Gillingham threatened mainly on the break and Cody McDonald fired a good chance over the bar from eight yards, before O’s suffered another blow on 39 minutes when Batt, who looked to race clear of the home defence, went down injured and was replaced by Robbie Simpson.
But the O’s continued to press and just before the break Cox sliced an effort wide under pressure after Lisbie provided the opening.
After the break Gillingham once again were quick out of the traps and McDonald beat Mat Baudry for pace down the left, but dragged his effort wide of the far post.
Orient continued with their patient build up, but rarely looked threatening until they levelled on 70 minutes following two corners in succession.
Cox swung the flag-kick in from the left and no-one picked up Bartley’s run as he powered into the area and sent a header from eight yards exploding into the net – his second goal in two games.
Straight after the goal Gary Sawyer replaced Scott Cuthbert, who had been booked shortly before hand as Slade reshuffled his defence.
As the game opened up Cox went close to grabbing a winner on 79 minutes when, after some slick build-up play down the right, he fired in a shot that looked to be arrowing into the far corner, only for Nelson to tip the ball away.
Then, four minutes from time the O’s went close again with a double chance. First Simpson saw his effort blocked by Nelson and the ball fell into the path of Lasimant, who had just replaced Lisbie, but although his shot beat the keeper Gillingham defender Legge somehow scrambled the ball off the line.
But there was to be no reprieve for Gillingham as Orient’s pressure finally told in the 90th minute when skipper Nathan Clarke sent over an awkward cross with his left foot from the right and When Nelson failed to gather Lasimant headed home at the far post – and Slade’s side were back to winning ways.
There was even time for Lasimant to go close again in the fourth minute of stoppage time, but he was denied by the knees of the Gillingham keeper, but it mattered not as the whistle went shortly after leaving the 898 fans singing: “We are top of the league, we are top of the league.”
Gillingham: Nelson, Martin, Legge, Akinfenwa (German 62), McDonald (Kedwell 81), Gregory, Dack (Fagan 55), Lee, Harriman, Barrett, Hassenthaler
Subs not used: Howard, Davies, Allen, Daniels.
Goals: Akinfenwa (2).
Gillingham bookings: Dack (13 foul), Akinfenwa (29 foul)
Leyton Orient: Larkins, Omozusi, Vincelot, Cuthbert (Sawyer 70), Baudry, Cox, Lisbie (Lasimant 86), Odubajo, Batt (Simpson 41), Clarke, Bartley.
Subs not used: Lee, Gorman, Ling, Grainger
Goals: Bartley (70), Lasimant (90)
Orient bookings: Omozusi (16 foul), Vincelot (54 unsporting behaviour), Cuthbert (68 foul)
Referee: Fred Graham
Attendance: 8,613 (inc 898 Orient fans)