Lukas Podolski put Germany in front and Lars Bender, on for the suspended Jerome Boateng, drove home the winner against Denmark.
Euro 2012: Denmark 1 Germany 2
Joachim Loew's inspired selection paid handsome dividends as Germany cemented their place in the Euro 2012 quarter-finals with victory against Denmark in Lviv on Sunday night.
The coach made his first change of the tournament, replacing the suspended Jerome Boateng with Lars Bender, who scored the match-winning goal with 10 minutes remaining after Denmark had fought bravely to join the Group B winners in the knockout stages.
Portugal's 2-1 victory over Holland in the other group match meant it is they who progress as runners-up. They face the Czech Republic in the quarter-finals on Thursday and Germany face Greece the following day.
Lukas Podolski put Germany in front in the 19th minute, but a goal from Michael Krohn-Dehli gave the Danes hope six minutes later.
Nicklas Bendtner's goal-bound header in the fifth minute was grasped by Manuel Neuer, who had to be secure with his handling as two Danish players loomed.
Germany remained camped in the Denmark half, playing a patient yet expressive game which led to Podolski marking his 100th Germany appearance with a goal in the 19th minute.
Thomas Muller provided a cross from the right-hand side of the penalty area which Mario Gomez flicked back to Podolski, who made no mistake from close range for his 44th international goal.
Germany's lead lasted only five minutes, though, before Krohn-Dehli's second goal of the tournament brought the Danes level.
He diverted Bendtner's header past Neuer from six yards out from a well-worked corner after a positive reaction from the Danes to falling behind.
Morten Olsen's side came closest to taking the lead in the second half when Jakob Poulsen's shot clipped the outside of the post.
With 10 minutes remaining the Danes' fate was sealed by Bender as the right-back galloped 40 yards to get ahead of a desperate last-ditch challenge from a Danish defender to finish past Stephan Andersen and maintain Germany's imperious form.
Follow us @SprtNationalUAE