PORTO ALEGRE, Brazil - Substitute Andre Schuerrle and Mesut Ozil scored in extra time and Germany survived Algeria's aggressive play with a 2-1 win Monday to reach the World Cup quarterfinals for the ninth consecutive time.
All three goals came in extra time after Algeria dominated for long stretches during the opening 90 minutes.
"It was a victory of will power," Germany coach Joachim Loew said. "We had major problems in the first half to organize the way we played. We made simple mistakes, which invited the opponents to start counter attacks."
Germany finally took the lead when Thomas Mueller provided a cross from the left flank that was slightly behind Schuerrle. The Germany forward dragged his left leg and backheeled the ball into the far corner in the 92nd minute, leaving goalkeeper Rais Mbolhi with no chance.
Ozil added the second in the 120th and substitute Abdelmoumene Djabou pulled one back in injury time for Algeria.
Three-time champion Germany will next face 1998 winner France on Friday at the Maracana Stadium in Rio de Janeiro.
With the temperature a chilly 14 degrees Celsius (57 degrees Fahrenheit) and a light rain falling at times, the pace was high at the Estadio Beira-Rio but the goals didn't come until the end.
Ozil thought he had put the result out of reach when he pounded in a rebound after a shot from Schuerrle was cleared off the line by defender Esseid Belkalem, but Djabou volleyed in a minute later to make the last seconds count.
Perhaps inspired by the "Disgrace of Gijon" at the 1982 World Cup, when Germany and Austria supposedly conspired to oust Algeria in the group stage, the northern African nation outmatched Germany's intensity for long stretches in an entertaining match.
Algeria was playing in the second round of the World Cup for the first time and thought it had taken the lead before a goal from Islam Slimani was waved off for offside in the 17th, one of many opportunities for the Algeria striker.
At the start of the second half, Germany put Schuerrle on for Mario Goetze in an attacking midfield and came out better organized.
In the 55th, Germany captain Philipp Lahm unleashed a hard shot that an outstretched Rais did well to push wide with his fingertips.
Still, Algeria continued to produce dangerous counterattacks. In the 72nd, Germany goalkeeper Manuel Neuer had to come out of his area to head away the danger with Slimani chasing.
In the 88th, Germany's inability to find the target turned theatrical for a moment when Mueller appeared to fall during a free kick.
Then the goals came, the rain intensified, and Germany took control.
Still, Algeria was cheered by its fans at the final whistle, while the Germany supporters appeared more relieved than content.
Germany: Manuel Neuer; Shkodran Mustafi (Sami Khedira, 70), Per Mertesacker, Jerome Boateng, Benedikt Hoewedes; Philipp Lahm, Bastian Schweinsteiger (Christoph Kramer, 109), Mesut Ozil, Toni Kroos, Mario Goetze (Andre Schuerrle, 46); Thomas Mueller.
Algeria: Rais Mbolhi; Faouzi Ghoulam, Essaid Belkalem, Rafik Halliche (Madjid Bougherra, 97), Mehdi Mostefa, Aissa Mandi; Medhi Lacen; Islam Slimani, Sofiane Feghouli, Saphir Taider (Yacine Brahimi, 78); El Arabi Hilal Soudani (Abdelmoumene Djabou, 100).