Denmark finished second in Group C by virtue of having a better disciplinary record than Slovenia after a dull draw with Serbia.
Neither side produced a performance that reflected their potential, but Denmark were the better team in a forgettable encounter in Munich.
Denmark ended on an identical record to Slovenia, meaning they had to be separated by the amount of yellow cards they received.
Both sides picked up six yellow cards on the pitch, but Slovenian coach Novakovic Milivoje was also booked in the first game, which Uefa do not count on their disciplinary statistics page, and that ultimately gave Denmark the slimmest of edges.
While Denmark and Slovenia both go through, Serbia are out – although none of the three teams won a group game.
Jonas Wind had a goal disallowed for Denmark in the first half because the ball had gone out of play before he bundled it over the line from a corner.
The Wolfsburg forward also slipped as he tried to connect with a smart flick-on from Rasmus Hojlund, slicing over the bar from a good position, and was substituted at the break.
Denmark continued to create chances despite a poor display by their standards. Alexander Bah headed wide and Christian Eriksen’s shot had to be parried behind for a corner.
Serbia, who knew they would be eliminated if they did not win because of Slovenia’s stalemate with England in the other Group C match, had just one shot on target that came in second-half stoppage time.
They had a goal ruled out when Luka Jovic’s shot bounced in off Denmark defender Joachim Anderson in the second half. Striker Jovic had been offside in the build-up.
Knowing their place in the last 16 was secure with a draw, a pragmatic Denmark side lacked ruthlessness. Jannik Vestergaard headed a corner delivery at Serbia goalkeeper Predrag Rajkovic, but the Danes rarely tested him in the second half.
As group runners-up, they have set up a tie with tournament hosts Germany in the next round.
“We are representing Danish football and we have to be happy about it,” said Denmark manager Kasper Hjulmand.
“It’s special of course when you play the hosts. It is a fantastic football country with a lot of passion.
“I really love football here in Germany and playing against them with the Danish team – it cannot be better. I can’t wait.”