Victory saw Denmark top Group B4 and secure promotion to League A.
Nicolai Jørgensen finished off a superb counter-attack to put the visitors in front three minutes before half-time at the Cardiff City Stadium before Martin Braithwaite's 88th-minute strike doubled the Danes' lead.
There was still time for Wales to pull one back through Gareth Bale's 31st international goal, but five minutes of stoppage time proved insufficient for Ryan Giggs' men to find an equaliser.
The promotion will see Denmark compete with Europe’s elite footballing nations in League A in the next Nations League cycle.
“It’s quite unique,” talismanic playmaker Christian Eriksen, who captained the team in the absence of regular skipper Simon Kjær, told TV2 Sport.
“The whole tournament has been nice to play in. The matches are different to friendly matches, which has made things more exciting, including for us as players. There was something to play for. It’s been fun,” he added.
Bale said he was disappointed not to win and praised the quality of the Danish team.
“The most important thing was the result for us,” he told Sky Sports.
“Obviously we wanted to perform well, which I thought we did in parts but ultimately we're disappointed not to win the group.
“They (Denmark) are a good team, they had a great World Cup and they're very highly ranked so we know they're a good team.”
Wales boss Giggs added: “I'm proud of the lads because they kept going to the end and excited me and excited the crowd. We need to learn the other side — the discipline that Denmark are so good at.”
Denmark, who reached the last 16 of this year's World Cup in Russia, are now guaranteed a play-off to qualify for Euro 2020, should they fail to reach the finals during regular qualifying.
Eriksen — who scored both goals when Denmark beat Wales in September — was nearly on target again in the third minute when given too much space before shooting narrowly over the bar from 20 yards.
Wales though almost took the lead after nine minutes when Paul Dummett, in his first competitive start for the country, found Bale 25 yards out.
But Denmark goalkeeper Kasper Schmeichel — the son of Giggs' former Manchester United team-mate Peter — managed to claw away the Real Madrid star's attempt.
Kasper Schmeichel pulls off an acrobatic save. Photo: Mads Claus Rasmussen/Ritzau Scanpix
Dummett's evening came to an unfortunate end when he went off injured, but his exit allowed substitute Chris Gunter to equal goalkeeping great Neville Southall's Wales record of 92 caps.
Minutes later, an open game saw Denmark take the lead.
Wales' Tom Lawrence lost possession some 25 yards from the Denmark goal.
Thomas Delaney sent Yussuf Poulsen racing down the right and Jørgensen, making excellent ground in support, ran to reach his pass and guide the ball between the legs of Wales goalkeeper Wayne Hennessey.
Both teams created chances in the second half, David Brooks going close for Wales with a shot from the edge of the box before a breakaway saw Poulsen shoot over the top of the crossbar from just inside the area in the 76th minute.
Schmeichel, with a save his celebrated father would have admired, produced a superb stop to keep out a Bale free-kick from 25 yards that appeared destined for the top corner.
The Danes appeared to have put the result beyond doubt when Braithwaite beat Hennessey with a powerful shot.
But Bale, racing onto a 40-yard through ball from Ashley Williams, gave Wales a lifeline 60 seconds later.