The Socceroos and the Danes were both in danger of crashing out of the tournament due to Tunisia taking the lead against reigning champions France in the other Group D fixture.
But Leckie had other ideas and delivered the knockout blow for the Danes with a superb solo effort in the 60th minute to send Australia into the last 16 for the first time since 2006.
The Melbourne City forward ran almost half the length of the pitch and twisted and turned Joakim Maehle before calmly finishing beyond Kasper Schmeichel.
Denmark offered little in response, albeit they were denied a penalty by an offside flag when Algerian referee Mustapha Ghorbal pointed to the spot following Harry Souttar's adjudged foul on Kasper Dolberg.
Graham Arnold’s men, who finished the group behind France on goal difference, will face Argentina in the second round on Saturday.
With the Socceroos starting the day in second spot courtesy of their win over Tunisia, the onus to attack was on Denmark.
The Danes were initially positive and dominated possession against a team 28 places below them in the FIFA world rankings, only to be frustrated in a forgettable opening period.
Australia goalkeeper Mathew Ryan tipped over from Mathias Jensen and unconventionally turned away a dangerous cross from marauding left-back Maehle, while Christian Eriksen dragged an effort wide.
Socceroos coach Arnold had spoken pre-match about "putting the game on the map a bit more" back home, as well as his desire to make the Australian public smile.
While his compact side were content to sit in and keep things tight, Middlesbrough's Riley McGree tested Schmeichel during a rare foray forward to show they could cause problems on the counter attack.
The pattern of play persisted into the second period before a goal in the other Group D game left both sides in grave danger.
News of Tunisia forward Wahbi Khazri opening the scoring against France appeared to have filtered through to the Al Janoub Stadium just before Leckie latched on to McGree's through ball to race clear and finish with aplomb.
Denmark needed at least two goals to avoid leaving Qatar early but, with their lack of cutting edge, even an equaliser seemed unlikely.
Australia endured a major scare 19 minutes from time when substitute Dolberg tumbled in the box before the penalty decision was swiftly overturned.
The spirited Socceroos, led impressively by Scotland-born centre-back Souttar, defended doggedly and deservedly survived six minutes of added time to upset the Euro 2020 semi-finalists and march on.