Gordon, 43, was forced into his first club minutes of the season after Alexander Schwolow was sent-off on the stroke of half-time.
Derek McInnes' men already led through Claudio Braga's 27th-minute strike.
But the visitors were forced to cling on in the second period and needed a miraculous save from Gordon deep into stoppage time to claw away Emile Acquah's downward header.
"He's always been capable of that type of save, and to do it at that moment was magnificent," said McInnes after the important victory.
"For me, that feels like the best three points of the season. I think a lot of people would have been questioning us at half-time, thinking this might be where Hearts run out of steam.
"Down to 10 men on a heavy pitch, everyone had to do one-and-a-half jobs, and everyone did it to the letter. I don't think anyone could deny us the win, and the big moment was Craig's save."
Gordon had played twice for Scotland in October to help his country qualify for a first World Cup since 1998.
However, he had not featured for Hearts since May due to a shoulder injury and then losing his place to Schwolow.
Dundee were seeking a fourth consecutive top-flight win for the first time since 1999 and had already taken points off Celtic and Rangers this season.
The home side were furious that the only goal was allowed to stand after Cammy Devlin took a free-kick from the wrong spot before the ball fell to Braga to drill in his 11th goal of the season.
Schwolow saw red for wiping out Tony Yogane on the edge of the box after a VAR review showed the Dundee player was not offside before the foul was committed.
But Hearts held out despite their numerical disadvantage to move one step closer towards ending the Old Firm's 40-year stranglehold on Scottish football.
Hearts remain three points clear of Rangers, with a game in hand, and six ahead of Celtic.
Rangers maintained their surge since Danny Rohl took charge in October with a second win over the Dons in six days.
Thelo Aasgaard's volley and a James Tavernier penalty secured an 11th win in 14 league games since Rohl arrived at Ibrox.
