André Schürrle became the 26th substitute goalscorer at the 2014 World Cup to send Germany through to the quarter-finals following an absorbing 120-minute encounter against an active Algeria.
The Chelsea winger swept in Thomas Muller's cross two minutes into extra-time following a lengthy period of German domination in which the lethal Müller missed enough chances to match Miroslav Klose's World Cup tally of 15.
Mesut Özil, who produced one of his most maddening displays, smashed in the eventual winner in the 120nd minute before Abdelmoumene Djabou finished for a neat consolation in stoppage-time.
Germany have now reached the quarter-final stage of every World Cup since 1982 and Joachim Löw's side will face France in a tantalising last eight tie.
Although Die Mannschaft's ingrained efficiency eventually restored order Algeria caused the three-times winners, bereft of centre-back Mats Hummels, great consternation in defence.
Eager goalkeeper Manuel Neuer needed little encouragement to dash from his line and compensate for the sluggish Per Mertesacker and jumpy Jérôme Boateng during a careless opening from the Germans. Neuer had 59 touches of the ball.
Löw withdrew Mario Götze at the interval for Schürrle and Sami Khedira's introduction for the injured Shkodran Mustafi helped re-energise Germany and they eventually breached the heroic Algerian goalkeeper Rais M'Bolhi.