Australia reached the knockout stage of the World Cup for the first time in 16 years after shocking Denmark.
The Danes, needing victory to progress, dominated possession but were caught out on the break when Australia scored the winner on the hour mark.
Denmark lost the ball in the Australian box and Mathew Leckie finished a brilliant counter attack with a low shot past Kasper Schmeichel.
Australia finish in second place in Group D on six points, only behind world champions France on goal difference.
Denmark meanwhile exit Qatar 2022 in disappointing fashion, with just one point from three games, sitting bottom of the group.
Australia will now play the winners of Group C - with Poland, Argentina and Saudi Arabia all in with a chance of topping the table - on Saturday (19:00 GMT).
Dark horses bolt as Denmark exit
Denmark came into the World Cup tipped by many fans and pundits as 'dark horses' after their impressive run to the semi-finals of Euro 2020 and a strong Uefa Nations League campaign in which they beat France home and away.
However, they failed to impress in Qatar and go home having scored only once in three Group D games.
Their attacking struggles were acknowledged by manager Kasper Hjulmand who made three changes from the defeat to France, all in attacking positions.
Martin Braithwaite, Brentford midfielder Mathias Jensen and Andreas Skov Olsen came in as Mikkel Damsgaard, Victor Nelsson and striker Andreas Cornelius dropped to the bench - but the changes made little difference.
The Danes' best chance came through Jensen in the first half, who forced Australia captain Mat Ryan into an impressive acrobatic save after being played through by a Braithwaite flick.
However, it was telling that Denmark's most threatening attacking outlet was left-back Joakim Maehle, who tested Australia with his probing runs but was not adequately supported by those further forward.
They demanded a penalty in the second half when Kasper Dolberg was hauled down in the area, however he was narrowly offside as the Danish campaign petered out.
Denmark continue their longest winless World Cup run, having failed to earn a victory in any of their past six games in the competition, with four of them draws.
Solid Aussies show spirit of 2006
Australia, the lowest seeded side in Group D, ran the game at their tempo and the largely uneventful encounter suited their needs perfectly, with a draw potentially enough to see them through having started the day second in the group on three points.
However just as the news of Tunisia taking a shock lead against France filtered through, which would have eliminated them on goal difference had they drawn here, Leckie sprang into action.
Dolberg lost the ball in the Australian box and his side was caught out on the break. Melbourne City winger Leckie ran confidently at the Danish defence, and struck left footed through Maehle's legs past Schmeichel inside the far post.
It ensured they reach the last 16 of the World Cup for the first time since 2006, when a star-studded side featuring Harry Kewell, Tim Cahill and Mark Schwarzer were only stopped by eventual champions Italy.
This team features far fewer big names but marshalled by captain and former Brighton and Arsenal goalkeeper Ryan, they have recovered from a 4-1 loss to France in their opening game - where they were naively open and picked apart by Kylian Mbappe and co - to grind out the results required.
It was Ryan who guided Australia through the nervy final six minutes of added time, claiming corners with aplomb.
A Cornelius header looped onto the roof of the net in stoppage time but a historic victory was secured.
Player of the match
SouttarHarry Souttar
Australia
Squad number19Player nameSouttar
Squad number7Player nameLeckie
Squad number13Player nameMooy
Squad number4Player nameRowles
Squad number26Player nameBaccus
Squad number16Player nameBehich
Squad number8Player nameWright
Squad number15Player nameDuke
Squad number14Player nameMcGree
Squad number22Player nameIrvine
Squad number2Player nameDegenek
Squad number1Player nameRyan
Squad number10Player nameHrustic
Squad number9Player nameMaclaren
Squad number23Player nameGoodwin
Denmark
Squad number10Player nameEriksen
Squad number13Player nameKristensen
Squad number23Player nameHøjbjerg
Squad number1Player nameSchmeichel
Squad number2Player nameAndersen
Squad number6Player nameChristensen
Squad number7Player nameJensen
Squad number5Player nameMaehle
Squad number11Player nameSkov Olsen
Squad number25Player nameLindstrøm
Squad number12Player nameDolberg
Squad number24Player nameSkov
Squad number14Player nameDamsgaard
Squad number9Player nameBraithwaite
Squad number26Player nameBah
Squad number21Player nameCornelius
Line-ups
Australia
Formation 4-4-2
1Ryan
2Degenek19Souttar4Rowles16Behich
7Leckie13Mooy22Irvine23Goodwin
14McGree15Duke
1Ryan2DegenekBooked at 57mins19Souttar4Rowles16BehichBooked at 4mins7LeckieSubstituted forHrusticat 89'minutes13Mooy22Irvine23GoodwinSubstituted forBaccusat 45'minutes14McGreeSubstituted forWrightat 74'minutes15DukeSubstituted forMaclarenat 82'minutesSubstitutes
3Atkinson5Karacic6Tilio8Wright9Maclaren10Hrustic11Mabil12Redmayne17Devlin18Vukovic20Deng21Kuol24King25Cummings26BaccusDenmark
Formation 4-3-3
1Schmeichel
13Kristensen2Andersen6Christensen5Maehle
7Jensen23Højbjerg10Eriksen
11Skov Olsen9Braithwaite25Lindstrøm
1Schmeichel13KristensenSubstituted forBahat 45'minutes2Andersen6Christensen5MaehleSubstituted forCorneliusat 70'minutes7JensenSubstituted forDamsgaardat 59'minutes23Højbjerg10Eriksen11Skov OlsenSubstituted forSkovat 69'minutesBooked at 75mins9BraithwaiteSubstituted forDolbergat 59'minutes25LindstrømSubstitutes
3Nelsson4Kjaer12Dolberg14Damsgaard15Nørgaard16Christensen17Stryger Larsen18Wass19Wind20Poulsen21Cornelius22Rønnow24Skov26BahReferee:Mustapha GhorbalAttendance:41,232Live Text
Match ends, Australia 1, Denmark 0.
Second Half ends, Australia 1, Denmark 0.
Attempt missed. Andreas Cornelius (Denmark) header from a difficult angle on the right is just a bit too high. Assisted by Christian Eriksen with a cross following a corner.
Corner, Denmark. Conceded by Mathew Ryan.
Corner, Denmark. Conceded by Milos Degenek.
Foul by Mikkel Damsgaard (Denmark).
Milos Degenek (Australia) wins a free kick in the defensive half.
Substitution, Australia. Ajdin Hrustic replaces Mathew Leckie.
Attempt missed. Alexander Bah (Denmark) right footed shot from the right side of the box is close, but misses to the right.
Attempt blocked. Keanu Baccus (Australia) right footed shot from outside the box is blocked. Assisted by Harry Souttar with a headed pass.
Joachim Andersen (Denmark) wins a free kick in the defensive half.
Foul by Jamie Maclaren (Australia).
Substitution, Australia. Jamie Maclaren replaces Mitchell Duke.
Attempt blocked. Jesper Lindstrøm (Denmark) right footed shot from outside the box is blocked. Assisted by Andreas Cornelius.
Attempt saved. Kasper Dolberg (Denmark) left footed shot from the centre of the box is saved in the bottom left corner.
Attempt blocked. Alexander Bah (Denmark) right footed shot from outside the box is blocked. Assisted by Andreas Cornelius.
Robert Skov (Denmark) is shown the yellow card for a bad foul.
Foul by Robert Skov (Denmark).
Keanu Baccus (Australia) wins a free kick on the right wing.
Offside, Australia. Kye Rowles tries a through ball, but Mitchell Duke is caught offside.
Get the latest results and goal notifications for any team at the Fifa World Cup by downloading the BBC Sport app: Appleexternal-link - Androidexternal-link - Amazonexternal-link