Lars Bender spared Germany from a shock Euro 2012 exit with the winning goal in a 2-1 victory over Denmark, whose tournament ended in Lviv.
The Bayer Leverkusen midfielder, playing as full-back for the national team, struck as Denmark were pushing for a goal which would have taken them through to the last eight at their opponents' expense, and just after Morten Olsen's side had seen a strong penalty appeal turned down.
Lukas Podolski put Germany in front in the 19th minute, but a goal from Michael Krohn-Dehli five minutes later lifted Denmark's spirits.
Germany controlled much of the game, but were nevertheless made to sweat as Denmark's belief and Portugal's 2-1 win over Holland ensured a tense finale which ended in their favour, clinching them top spot in Group A with a perfect record and a clash with Greece in Gdansk on Friday.
Joachim Low's side began with authority and the diligent Thomas Muller went close twice early on, but Stephan Andersen showed lightning reactions to deny his second attempt in the sixth minute.
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. Muller provided a low cross which Mario Gomez flicked intelligently back to Podolski, who left nothing to chance with a powerful shot from seven yards out.
Germany's lead lasted only five minutes, though, before Krohn-Dehli's second goal of the tournament brought the Danes level.
He diverted Nicklas Bendtner's header past Manuel Neuer from six yards out from a well-worked corner after a positive reaction from the Danes to falling behind.
Jakob Poulsen went within inches of putting Denmark in front five minutes into the second half when his shot grazed the outside of the left-hand post with Neuer beaten.
Just as Low's side were showing the first signs of tension, they regained the lead from an unlikely outlet. Mesut Ozil's throughball was intended for Miroslav Klose, but it was too far in front of him but inviting for full-back Bender, who coolly took his first international goal in the 80th minute to take Germany through and knock Denmark out of Euro 2012.