Finland outshot the Danes 11-4 in the opening period but scored only once at 14:29 through Minnesota Wild centre Mikael Granlund.
Jarno Koskiranta and Patrik Laine added a goal apiece in the second period, while Montreal Canadiens centre Lars Eller scored a powerplay goal for Denmark.
The Danes substituted their goalie for a sixth field player with 2:18 remaining and Jussi Jokinen took full advantage by scoring an empty-netter.
Granlund rounded off the scoring with his second of the match with 1:53 to go.
"We knew there were no free tickets to Moscow," Finland head coach Kari Jalonen said. "We had to pay the price. Denmark had a great tournament here. It was tough to break their defence. But I think we won deservedly today."
Despite the loss, Denmark still earned its best world championship result ever with an eighth-place finish and national coach Jan Karlsson said the Danes' best days on the ice are ahead of them.
"There is huge development potential with many of the players," he told Rtizau.
Defenseman Oliver Lauridsen agreed with his coach, saying that Denmark's strong showing at this years' IIHF world championships should encourage the club's many young players.
"The young players coming up need to know that we are closer to the top than we think. We have become a major ice hockey country and have the ability to make it to the quarter-finals if we play up to our abilities," he said.
In Thursday's other quarter-finals, reigning world champions Canada boosted their hopes of retaining their title as they thrashed Sweden 6-0, while the US beat Czech Republic 2-1 in a penalty shootout and Russia downed Germany 4-1.