Algeria gave Germany an unexpected scare before two extra-time goals sent the three-time champions into a ninth successive World Cup quarter-final.
The Africans had Germany rattled for long but Andre Schurrle’s inventive flick from Thomas Muller’s pass and Mesut Ozil’s late close-range strike ensured their progress.
Algeria scored a late consolation through Abdelmoumene Djabou.
Germany progresses to face France in Rio de Janeiro on Friday.