The Chelsea forward turned home Thomas Muller's cross before the Arsenal playmaker fired in just before Abdelmoumene Djabou scored a consolation in the dying seconds Germany secured a place in the quarter-finals of the World Cup after Andre Schurrle and Mesut Ozil struck in extra-time to seal a win 2-1 over Algeria on Monday.
After a pulsating 90 minutes in Porto Alegre had ended goalless, Chelsea forward Schurrle - on as a half-time substitute for Mario Gotze - cleverly flicked in Thomas Muller's low cross two minutes into extra-time to give Germany the lead.
Ozil added a second late on to wrap up victory for Joachim Low's side, before Algeria, who performed admirably throughout, gained a consolation through Abdelmoumene Djabou.
The result meant Algeria were unable to exact revenge for the "Disgrace of Gijon", when West Germany and Austria played out a mutually beneficial 1-0 scoreline that saw both sides through from the group at the expense of Algeria in the 1982 finals in Spain.
With many pointing to that infamous match as motivation for Vahid Halilhodzic's men in the build-up, Algeria flew out of the blocks in the opening 20 minutes, cutting through the German backline on a number of occasions and seeing an Islam Slimani goal disallowed for offside.
The African nation - making their first appearance in the second round - continued to impress, but Germany, who will now face France at the Maracana on Friday, finished the stronger and remain on course to reach the semi-finals of a fourth successive World Cup.
Algeria made a flying start and Manuel Neuer had to make a sliding tackle to deny Slimani an effort on goal from wide on the left in the ninth minute, after the goalkeeper had initially misjudged a charge from his line.
Sofiane Feghouli wasted a good position six minutes later, blazing the ball wildly across goal from the byline with two team-mates better placed.