Elgin secured a club record fourth league win in a row with a last-minute Hugh Dickson goal which hoisted them closer to a play-off spot and left Arbroath stunned.
The home side dominated the game for long spells, but were left to regret missing a first- minute penalty given when Elgin goalkeeper Kieron Renton pulled down Gavin Swankie.
Jay Stein's soft kick was, however, well saved by the keeper who dived low to his right to gather the ball.
Arbroath controlled much of the opening period and Swankie almost scored in the 24th minute with a dipping 20-yard free-kick which Renton did well to tip over the bar.
Elgin didn't threaten the home goal until the 39th minute when Stuart Easton's 25-yard drive was deflected past the post.
Swankie again came close for Arbroath in the 48th minute, but his shot was blocked by Renton.
Mark Booth had the ball in the net for Elgin after 75 minutes, but the flag had already been raised for offside.
The visitors seemed content to play for the draw, but with just 60 seconds left the Arbroath defence failed to clear a free-kick and Dickson pounced to fire the loose ball high into the net for a dramatic winner.
"I would have been happy with a point, but all credit to the players for keeping going and grabbing a late winner," said Elgin manager Brian Irvine.
"We were the better team for much of the game" said Arbroath manager John McGlashan. "But we didn't get the rub of the green. These things happen in football and I can't criticise my players because they all gave 100 per cent."