Germany set up a Euro 2012 quarterfinal with Greece on Sunday with a 2-1 win over Denmark, who were eliminated with the defeat.
Germany win Group B ahead of Portugal, who sent home the Netherlands with the same scoreline in Kharkiv.
The Germans needed a solitary point from the match against Denmark, and it appeared headed for a draw until right-back Lars Bender, a replacement for the injured Jerome Boateng, side-footed Mesut Ozil's through ball home with 10 minutes remaining.
Germany advance with a perfect record of three wins in three, beating the Portuguese 1-0 and the Dutch 2-1 on goals all scored by Mario Gomez.
Denmark would have qualified had they beaten Germany or if they had drawn and the Netherlands had beaten Portugal.
Lukas Podolski, winning his 100th cap, scored the opener for the Germans on 19 minutes, slamming home from six yards out after Thomas Muller's low cross from the right was missed by striker Mario Gomez.
Denmark equalized on 24 minutes through Michael Krohn-Dehli, who leapt above Mats Hummels to redirect a Nicklas Bendter header into the net from close range.
Germany earn a quarterfinal against Group A second-place team Greece, while the Portuguese, finishing second, will play Group A winners the Czech Republic.