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, which has now advanced past the second round at nine consecutive World Cups, will next face 1998 winner France on Friday at the Maracana Stadium in Rio de Janeiro.
With the temperature a chilly 57 degrees 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.
France 2, Nigeria 0: Paul Pogba scored with a late header to finally break Nigeria’s stubborn resistance and Joseph Yobo added an own-goal as France reached the World Cup quarterfinals.
Nigeria goalkeeper Vincent Enyeama had just made a superb save to tip over Karim Benzema’s header, but he flapped at the ball from the ensuing corner and Pogba pounced in the 79th minute to nod in his first goal of the tournament.
Pogba atoned for a scrappy first half in which he gave the ball away carelessly and placed a volley too close to Enyeama. Scoring such a crucial goal will boost his confidence heading into the last eight against Germany, which beat Algeria later.
Yobo turned the ball into his own net in stoppage time under pressure from France substitute Antoine Griezmann — who made a big difference after replacing the ineffective Olivier Giroud in the 62nd.
At the final whistle, France’s relieved players danced in front of their fans as dreams of a repeat run to the final — just like in 2006 — moved a step closer.
France started slowly and finished strongly in the second-round match.
African champion Nigeria had a goal ruled out for offside in the 19th minute after Emmanuel Emenike poked home Ahmed Musa’s cross from the left, but wasted a lot of second-half possession.