Andre Schuerrle and Mesut Ozil struck in extra time to earn Germany a 2-1 win over Algeria in a pulsating last 16 clash in Porto Alegre on Monday and a quarterfinal date with France.
Chelsea forward Schuerrle broke the deadlock in the 92nd minute, with Arsenal's Ozil adding a second in the 120th minute.
Abdelmoumene Djabou struck in the first minute of stoppage time to give Algeria a consolation goal.
This was Algeria's first ever appearance in the knockout stages and they covered themelves with glory, taking the game to the three-time champions.
Sporting Lisbon striker Islam Slimani had a goal disallowed for offside in the first half while Germany's best early chance came as the break beckoned, when only the lightning reflexes of Algeria keeper Rais Mbolhi denied first Toni Kroos' and then Mario Goetze from the rebound.
Germany coach Joachim Loew introduced Schuerrle for Goetze after the interval and he almost made an immediate impact, his 48th minute drive only narrowly deflected.
Mbolhi then made a superb flying fingertip save to deny Phillip Lahm.
In an enthralling evening's entertainment at this southern port city Mbolhi once again did the north African's proud, punching away Thomas Mueller's header with 10 minutes of regulation time remaining.
With the sides deadlocked, extra time was required, and Schuerrle finally was the man to find a way past Mbolhi, flicking the ball with the inside of his heel at close range after Mueller's cross from the left in the 92nd minute.
Ozil then struck before Djabou's contribution.
Friday's quarterfinal at Rio de Janeiro's Maracana is a repeat of the 1986 semifinal won by the then West Germany.