The game was suspended for 20 minutes in the first half due to the weather before Danish defender Joachim Andersen went from hero to zero soon after the break when his close-range finish was disallowed for offside before he conceded a penalty converted by Havertz in the 53rd minute.
Nico Schlotterbeck earlier had a goal ruled out for a foul in the build-up as Germany started strongly in front of an expectant crowd, but Denmark grew into the game and went close either side of halftime.
The hosts established an unassailable lead in the 68th minute, however, when Musiala ran on to a ball over the top and curled home his third goal of the tournament to put Germany into the last eight, where they will face Spain or Georgia.