Derek Townsley - making just his second start for Gretna since August - grabbed a last-gasp winner to stretch their lead at the top of the table and preserve their 100 per cent home league record.
Hard-working Elgin looked set for a well-earned point before Townsley's point-blank strike.
The visitors went in front in the 31st minute with a quality goal from Andy Roddie. He stroked a 25-yard free-kick over the defensive wall and wide of diving keeper David Mathieson.
But Gretna were back on level terms two minutes later. Kenny Deuchar met a Gavin Skelton corner with a downward header that Elgin keeper Kieron Renton palmed out only for David Bingham to stab the ball home.
Gretna keeper Mathieson was at full stretch to save a fierce Stephen Donnachie first timer five minutes into the second half.
But a couple of minutes later Elgin were reduced to 10 men when defensive lynchpin Craig Higgins went off with a cut after a clash of heads with Ryan McGuffie.
And while he was off, full-back Hugh Dickson handled a Steven Tosh cross, and the ex-Aberdeen man stepped up to take the spot-kick but fired weakly and Renton saved.
The game looked to be heading for a draw before Dickson cleared a Gavin Skelton header off Elgin's line, and when the ball was crossed back into the crowded area by substitute David Graham, McGuffie headed on and Townsley side-footed home from a couple of yards.
Afterwards, goal hero Townsley said: "Honestly, the goal would have been harder to miss. You could feel the tension before I scored. Elgin were difficult to break down but we got the rub of the green, and hearing that Peterhead could only draw made the result that much more important."
Gretna boss Rowan Alexander admitted: "We got out of jail. Elgin stopped us playing and next season they'll be challenging at the top."
Elgin manager David Robertson said: "I thought we did enough to get a point. I couldn't ask any more from the boys - they deserve a huge amount of credit."