Wales missed out on promotion to the top tier of the Nations League as Denmark won a passionate Cardiff contest 2-1.
Nicolai Jorgensen gave Denmark a half-time lead and Martin Braithwaite's superb volley two minutes from time doubled their advantage to seemingly end Welsh hopes.
But Gareth Bale's instant response, sliding home his 31st international goal after rounding Denmark goalkeeper Kasper Schmeichel, had the visitors hanging on at the end.
Wales were not short of endeavour against opponents who had reached the last 16 of the World Cup in the summer, but even with the fit-again Bale in their ranks they often lacked the craft to worry the streetwise Danes.
Taking out the 3-0 defeat to Slovakia in September, when an amateur team played because of a row over the squad's commercial rights, Denmark have now conceded only twice in 12 games.
It is that defensive durability on which Denmark build their game and why it is they, and not Wales, who will be joining the elite of European football.
Denmark are also guaranteed a play-off to qualify for Euro 2020, should they fail to reach the tournament during the regular qualifying process, while a youthful Wales side should be better for this experience when the qualifiers start in March.
Bale returned after sitting out Wales' October action and Denmark's own talisman Christian Eriksen was also back after missing the last two games through injury.
The Tottenham playmaker had scored both goals when Denmark beat Wales 2-0 in Aarhus in September and Denmark attempted to get their creative spark on the ball at every opportunity.
Aaron Ramsey was deployed in a deeper role than he is accustomed for Wales and part of his brief was to monitor Eriksen's forays forward.
The signs were ominous for Wales as Eriksen strode forward as early as the third minute to send a 25-yard drive whistling over the crossbar.
Jens Stryger Larsen then went unchecked down the left and his over-hit cross almost embarrassed Wayne Hennessey in the Wales goal.
But in what was proving a lively opening Wales settled and went close to scoring twice inside a minute.
Paul Dummett, starting a competitive game for the first time nearly four-and-a-half years after making his debut, set up Bale for a 25-yard attempt that Schmeichel batted aside.
Wales had an even better chance moments later when Ramsey's backheel allowed David Brooks to cross and James Chester headed wide from six yards out.
Tom Lawrence saw his 20-yard effort deflected over by Andreas Christensen and Bale headed wide after Connor Roberts had stood up a cross to the far post.
But Denmark were in the ascendancy before Dummett's departure to injury allowed Chris Gunter to equal Neville Southall's record of 92 Wales.
Delaney had failed to connect with Martin Braithwaite's inviting ball before Wales were exposed by a lightning counter-attack.
Yussuf Poulsen raced onto Delaney's pass for Jorgensen to slot the ball through the legs of Hennessey.
Wales needed an instant second-half response and almost got it when Bale broke down the right and crossed with the outside of his foot.
Brooks lifted the ball on the volley over Schmeichel and the crossbar, but the Bournemouth youngster was a handful whenever he was allowed to run at defenders.
Bale almost equalised when his free-kick was brilliantly clawed away by Schmeichel and tempers threatened to boil over in the final moments after some poor challenges.
There was even more late drama as Braithwaite and Bale struck inside a minute, but Denmark held on to clinch promotion and leave Wales in second spot ahead of the relegated Republic of Ireland.