Leckie put Australia ahead on the hour when he dribbled around Joakim Maehle before sending a low finish past Kasper Schmeichel at the Al Janoub Stadium.
The result means Australia will play in the tournament's knockout stage for the first time since 2006 in Germany, where they were eliminated by eventual champions Italy in the round of 16. Denmark are eliminated after having finished last in Group D.
The game began at a pedestrian pace with few genuine scoring chances in the first 20 minutes for either side.
Denmark made the first early inroads toward goal and Australia goalkeeper Mathew Ryan saved with his feet after Maehle's cut-back ricocheted off Harry Souttar inside the six-yard box.
Australia's first attempt came just before the half hour when Riley McGree sent a tame effort from the edge of the penalty area straight at Schmeichel.
Denmark dominated possession but lacked potency in attack. Jesper Lindstrom created a rare moment of discomfort for the Socceroos' defense when he made a mazy run into the box before seeing his pass to Mathias Jensen blocked. The ball fell to Christian Eriksen, whose long-range shot flew wide of the left post.
Despite seeing little of the ball in their opposing half, Australia looked more likely to score. Mitch Duke arguably had the best chance of the first half after Australia cut through Denmark's defense with a series of slick passes.
But the Fagiano Okayama winger's effort from distance lacked venom and was comfortably saved by Schmeichel.
Craig Goodwin then sent a dangerous cross to the edge of the six-yard box before Andreas Christensen cleared.
Denmark completed more than twice as many passes as Australia in the second half and continued to dictate the tempo early in the second.
But Graham Arnold's men posed a constant threat on the counterattack and they caught Denmark's defense napping when McGree sent a perfectly weighted pass into the path of Leckie, who turned and weaved his way past Maehle before angling a left-footed shot through the defender's legs and into the far corner.
Australia were suddenly brimming with confidence. Aziz Behich danced into the box before having the ball swiped from his feet, and Leckie almost found himself with a clear run on goal after Jackson Irvine's diagonal pass.
Denmark had their chances to equalize in the closing minutes. Substitute Andreas Cornelius sent a free header well wide of the target and Kasper Dolberg was dispossessed by Souttar after a dangerous foray into the box.