It was Denmark's second title in the last three Games, having played in all three finals in Rio - where they won - Tokyo and Paris.
Germany, who knocked out defending champions France in the quarter-finals, were never in the mix and trailed throughout after levelling for 1-1.
Spain edged out Slovenia 23-22 in the bronze medal match earlier on Sunday.
The Tokyo silver medallists racked up goals at breakneck speed while the Germans struggled to break through the Danish defence, trailing by nine points after 30 minutes - the biggest ever halftime deficit in an Olympic gold medal match.
Germany, who won bronze in Rio, tried to make headway as the game wore on. Centre back Juri Knorr poured in six points while right back Renars Uscins and line player Jannik Kohlbacher each contributed four.
But they were no match for the undefeated Danes, notably right back Mathias Gidsel who scored 11 goals.
It was the first time since Croatia won gold at the Athens Games in 2004 that a handball team had won the gold without losing a single Olympic match.