Lars Bender scored the winner 10 minutes from time as Germany took their place in the quarter-finals of Euro 2012 as convincing winners of Group B.
The 23-year-old Bayer Leverkusen player poked in late on to end Denmark's dream of repeating their heroics of 1992.
Germany had taken a 19th-minute lead through Lukas Podolski, only for Michael Krohn-Dehli to head in six minutes later and give Denmark hope.
Euro 2012: Germany's Bender ends Denmark hopes
Germany, who qualify with a 100% record, play Greece in the last eight.
For much of this game, this was a dominant display by Germany, inspired by Sami Khedira's midfield generalship, Thomas Mueller's prodigious work on the wings and a workrate and ambition that glowed throughout the team.
The long journeys from Germany's team base in Poland to Ukraine have not gone down well with the squad but having topped the group with victory in Lviv, they have earned a quarter-final in Gdansk, the city where they are based.
The last time Denmark and Germany met in a competitive fixture had been memorable for very different reasons. The final of the 1992 European Championship saw the Danes, late replacements for the banned Yugoslavia, beat the Germans in the final to complete one of the most surprising tournament victories in history.
Denmark have struggled to escape the shadow of that victory ever since but with the sublime young talents such as Christian Eriksen in the side there was a sense of optimism that 20 years on the seemingly impossible might just be possible all over again.
Germany were in no mood for a repeat, however. For long periods of this match Joachim Loew's side were untouchable in possession with Mueller and Bastian Schweinsteiger dictating from midfield.
Whether breaking past an opponent from wide on the right flank, or erupting with dramatic suddenness through the middle of a defence, Mueller's early runs were an exhilarating blend of grace and devastation.
The Bayern Munich midfielder was a constant danger, but twice in the early moments he spurned good chances, failing to make clean contact when the ball broke to him six yards from goal and shooting narrowly over with the goal at his mercy.
It was no surprise when Mueller created the opening goal for Germany, exchanging passes with Mesut Ozil, before cutting the ball back across the penalty area from the right where Podolski thumped it ruthlessly beyond Denmark goalkeeper Stephan Andersen.
It was the perfect way to celebrate becoming the youngest European player, at the age of 27, to reach 100 caps.
Denmark were bystanders for much of the opening period, unable to prevent or disrupt the German passing carousel and relying on intermittent long-range attacks. But what became clear quite quickly was their dominance at set-pieces.
Arsenal striker Nicklas Bendtner had won an early header in the penalty area and when he rose again to meet Lars Jacobsen's 23rd-minute corner, Germany were found wanting. The Dane rose majestically to direct the ball back across goal, where Krohn-Dehli headed it decisively beyond Germany goalkeeper Manuel Neuer.
But while Denmark visibly grew in confidence after the goal, Germany continued to dominate. Mario Gomez was always on hand to provide the German attack with a focal point and might have done better on two occasions before half-time when the ball broke kindly to him.
Euro 2012: Podolski scores on 100th appearance
Khedira was also guilty of wastefulness, exchanging passes with Gomez only to prod the ball wide with the outside of his right foot when the ball broke to him.
Denmark were, however, unbowed. Starved of possession and chasing shadows, the clenched fist of their coach Morten Olsen at half-time said it all.
It had been a gesture of unexpected defiance in the face of German domination and his time almost responded.
Denmark looked a different side early in the second half and should have snatched an unlikely lead when Bendtner collected Simon Poulsen's clever pass in the penalty box before laying the ball off to Jakob Poulsen, who skimmed the outside of the post with his low shot.
The fluency Germany had found for long periods was being disrupted by a Denmark side that tackled, battled and denied space, their uncomplicated, direct approach putting their more celebrated opponents under serious duress.
The introduction of Bayern Leverkusen striker Andre Schuerrle appeared to help Germany regain their dynamism, however. The 21-year-old almost made an immediate impact, gathering Khedira's delightfully-weighted pass before directing a fierce, low shot across goal which Andersen did well to push to safety.
Germany by the numbers
Lukas Podolski has become the youngest European player to reach 100 caps.
Germany were playing with their youngest line-up in a European Championship match with an average of 25 years and 107 days.
This is the first time Germany have completed a European Championship group stage with a 100% record.
Source: Opta Sports
Bendtner was unfortunate moments later when he stretched to lift a shot high into Neuer's hands, while Germany defender Holger Badstuber pulled at his shirt.
But with Denmark tiring, Bender broke forward covering 60 yards to take advantage of Simon Poulsen's slip and roll the ball beyond Andersen. It was the youngster's first goal for Germany on his first start for his country and the moment that decided the outcome of Group B.
Agger rose high above Badstuber to head over as Denmark continued to push but the chance had gone and the dream was over.
Full Time The referee blows his whistle to end the game.
Daniel Agger is caught offside. Indirect free kick taken by Manuel Neuer.
The assistant referee signals for offside against Andre Schurrle. Stephan Andersen restarts play with the free kick.
The assistant referee signals for offside against Miroslav Klose. Stephan Andersen takes the direct free kick.
Free kick awarded for a foul by Christian Poulsen on Miroslav Klose. Bastian Schweinsteiger produces a strike on goal direct from the free kick.
Michael Krohn-Delhi is penalised for handball and concedes a free kick. Manuel Neuer takes the direct free kick.
The referee blows for offside against Simon Poulsen. Free kick taken by Manuel Neuer.
Substitution Thomas Muller goes off and Toni Kroos comes on.
Outswinging corner taken right-footed by Lars Jacobsen, Header on goal by Daniel Agger from inside the box goes harmlessly over the target.
Substitution Jakob Poulsen goes off and Tobias Mikkelsen comes on.
Assist by Mesut Ozil.
79:38 Goal scored
Goal! - Lars Bender - Denmark 1 - 2 Germany A goal is scored by Lars Bender from inside the penalty box to the bottom left corner of the goal. Denmark 1-2 Germany.
Substitution Niki Zimling leaves the field to be replaced by Christian Poulsen.
The ball is delivered by Thomas Muller, Daniel Agger makes a clearance.
The assistant referee flags for offside against Miroslav Klose. Direct free kick taken by Nicklas Bendtner.
Substitution (Germany) makes a substitution, with Miroslav Klose coming on for Mario Gomez.
The ball is crossed by Sami Khedira, clearance by Michael Krohn-Delhi.
Niki Zimling takes a shot. Save by Manuel Neuer. Short corner taken by Michael Krohn-Delhi from the left by-line. Centre by Christian Eriksen.
Michael Krohn-Delhi sends in a cross, clearance made by Holger Badstuber.
Andre Schurrle takes a shot. Save made by Stephan Andersen.
Direct free kick taken by Bastian Schweinsteiger.
Substitution Andre Schurrle on for Lukas Podolski.
Bastian Schweinsteiger takes a shot. Blocked by Simon Kjaer. Free kick awarded for a foul by Nicklas Bendtner on Bastian Schweinsteiger.
Thomas Muller crosses the ball, Simon Kjaer manages to make a clearance.
Corner taken left-footed by Mesut Ozil from the right by-line, save by Stephan Andersen.
Sami Khedira sends in a cross, Niki Zimling makes a clearance.
Thomas Muller delivers the ball, clearance by Daniel Agger.
Simon Poulsen is ruled offside. Direct free kick taken by Mats Hummels.
Unfair challenge on Niki Zimling by Thomas Muller results in a free kick. Daniel Agger takes the direct free kick.
The ball is delivered by Simon Poulsen. Effort from the edge of the area by Jakob Poulsen goes wide of the left-hand upright.
Mario Gomez produces a right-footed shot from outside the penalty box and misses left.
Centre by Philip Lahm, save by Stephan Andersen.
A cross is delivered by Mesut Ozil, Simon Kjaer gets a block in.
The referee penalises Thomas Muller for handball. Direct free kick taken by William Kvist Jorgensen.
The referee blows his whistle to start the second half.
45:00 +1:10 Half time
Half Time The referee calls an end to the first half.
Simon Kjaer takes a shot. Bastian Schweinsteiger gets a block in.
Jakob Poulsen sends in a cross.
Corner taken by Christian Eriksen from the left by-line played to the near post.
Nicklas Bendtner concedes a free kick for a foul on Mats Hummels. Mats Hummels takes the free kick.
Free kick awarded for an unfair challenge on Stephan Andersen by Mario Gomez. Stephan Andersen takes the direct free kick.
Effort on goal by Sami Khedira from deep inside the penalty area misses to the right of the goal.
Niki Zimling takes a shot. Blocked by Mats Hummels.
The ball is delivered by Sami Khedira.
Free kick awarded for a foul by Simon Kjaer on Thomas Muller. Mesut Ozil takes the free kick. Lukas Podolski produces a left-footed shot from just outside the area that goes harmlessly over the bar.
Inswinging corner taken by Mesut Ozil from the right by-line played to the near post, clearance by Daniel Agger.
Free kick awarded for a foul by Daniel Agger on Thomas Muller. Mesut Ozil delivers the ball from the free kick left-footed from right wing, save by Stephan Andersen. Short corner taken by Bastian Schweinsteiger. Effort on goal by Mario Gomez from inside the box misses to the right of the target.
Unfair challenge on William Kvist Jorgensen by Philip Lahm results in a free kick. Free kick taken by Simon Kjaer.
Michael Krohn-Delhi has an effort at goal from long distance that goes wide left.
Lars Bender sends in a cross, Daniel Agger makes a clearance.
The assist for the goal came from Nicklas Bendtner.
24:26 Goal scored
Goal! - Michael Krohn-Delhi - Denmark 1 - 1 Germany Michael Krohn-Delhi scores a headed goal from close range. Denmark 1-1 Germany.
Outswinging corner taken by Lars Jacobsen from the right by-line.
Mario Gomez gives away a free kick for an unfair challenge on Niki Zimling. William Kvist Jorgensen restarts play with the free kick.
Assist by Mario Gomez.
18:26 Goal scored
Goal! - Lukas Podolski - Denmark 0 - 1 Germany Goal scored by Lukas Podolski from inside the penalty box to the top right corner of the goal. Denmark 0-1 Germany.
Mesut Ozil fouled by Niki Zimling, the ref awards a free kick. Mesut Ozil delivers the ball from the free kick left-footed from right channel.
Unfair challenge on Mats Hummels by Nicklas Bendtner results in a free kick. Lars Bender restarts play with the free kick.
Nicklas Bendtner has an effort at goal from long distance that goes wide left.
Mario Gomez produces a left-footed shot from just outside the area that goes harmlessly over the bar.
The ball is delivered by Lukas Podolski, Thomas Muller takes a shot. Save by Stephan Andersen.
Simon Poulsen produces a cross, blocked by Lars Bender. Inswinging corner taken by Michael Krohn-Delhi, Nicklas Bendtner takes a shot. Save by Manuel Neuer.
The ball is crossed by Sami Khedira, Lars Jacobsen makes a clearance.
Shot on goal by Thomas Muller from just inside the area goes over the target.
Centre by Sami Khedira.
The referee blows for offside. Mats Hummels restarts play with the free kick.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.