(CNN) -- Extra-time goals from Mesut Ozil and Andre Schurrle spared Germany's blushes against Algeria in the World Cup last 16 tie at Port Alegre on Monday.
Following 90 minutes of stalemate it was Joachim Low's side who finally broke the deadlock in the second minute of extra time when Thomas Muller squared the ball for Schurrle to cleverly back heal the ball past goalkeeper Rais Mbolhi.
Ozil drilled in a shot to double the lead in the final minute of the second extra period before Abdelmoumene Djabou pulled one back for Algeria in injury time.
It was a cruel end to what was a brave performance by Vahid Halilhodzic's side who were looking to settle an old score from the 1982 World Cup.
Algeria were eliminated at the group stage at the tournament held in Spain after West Germany and Austria contrived a result (a 1-0 win to the Germans) which guaranteed both European teams would qualify for the knockout stages.
Thirty-two years after the so-called "Disgrace of Gijon" it was fitting that Algeria's first last 16 match in the World Cup was against Germany.
Spurred on by history, the Desert Foxes got off to a flying start and perhaps deserved more for their frequent early raids into the heart of the German defense.
Islam Slimani served warning of Algeria's threat in the eighth minute as he scampered unchallenged down the left after a German attack broke down. The danger was only averted when Manuel Neuer rushed out of his area to tackle the Sporting Portugal striker.
Nine minutes later Slimani looked to have scored his third goal of the tournament when he headed in El Arabi Soudani's superb cross, but was adjudged to be offside -- TV replays showed the referee's assistant had made the correct call.
As the half wore on Germany came back into the game but were still vulnerable to the counter and were lucky when, in the 39th minute, Aissa Mandi's thunderous 25-yard drive ricocheted off the boot of defender Jerome Boateng and bounced narrowly wide.
Moments later at the other end, Germany were denied themselves as Mbolhi pulled off an amazing double save from Toni Kroos then Mario Gotze.
Schurrle replaced Gotze at the start of the second half -- a change which made Germany more purposeful in attack.
In the 54th minute, Muller laid the ball on for captain Philipp Lahm whose shot from 18 yards out produced an outstanding fingertip save from Mbolhi.
Algeria's rampant forays forward were less frequent but no less alarming for the Germany's back four who continued to struggle with Slimani's menacing runs.
As the game entered the final 15 minutes of normal time it was Germany who increasingly looked likely to score.
Muller looked certain to head in substitute Sami Khedira's cross in the 80th minute but could only fire straight at Mbolhi and ten minutes later Bastian Schweinsteiger missed the chance to head a late winner.
Schurrle's 92nd minute strike calmed German nerves before Mehdi Mostefa got them jangling again eight minutes later with a close range strike which went wide.
But when Ozil scored Germany's second in the 119th minute they were home and dry despite Djabou's late goal.
Low's side can now look forward to a quarterfinal against France at the Maracana on Friday.