A tight contest throughout was effectively decided by Niklas Ekberg's shot into an empty net with just over a minute to play, setting up a semi-final clash with Hungary and ending Denmark's challenge for gold.
Ulrik Wilbek's side, winners of the European Championship in January, did not have the best of it in the preliminary stage and they qualified second in Group B, with a minus goal difference, while Sweden lost twice on their way to third position in Group A.
It was an even start to the game, with neither side gaining the upper hand and the scoreboard was 6-5 in Denmark's favour after 15 minutes.
The tight nature of the game continued after the break as Denmark were able to eradicate their deficit and claw the scores back level to 17-17 with 13 minutes remaining.
That advanced to 22-22 with five minutes to play as a grandstand finish looked on the cards with nothing separating the two teams.
After a lengthy spell without a goal, Sweden took a decisive lead when Ekberg threw in to put his side 23-22 ahead with 75 seconds to play and they were able to hold on and secured a two-goal cushion with the final throw of the game.
Doder finished top-scorer with six for Sweden, who celebrated long after the final whistle, while Hans Lindberg also threw in six for Denmark in a losing cause.