Niclas Fullkrug's goal rescued a point against Spain but Germany's fate will be decided in the last round of group games in Qatar
Germany salvaged a late draw against Spain in their World Cup Group E clash in Qatar on Sunday, but Hansi Flick's men must now beat Costa Rica to stand any chance of reaching the knockout stages of the tournament.
Germany had appeared on course for a second successive defeat in Qatar when Alvaro Morata's smart finish at the front post on 62 minutes gave Spain the lead at Al Bayt Stadium.
But Germany roused themselves, finding the equalizer when substitute Niclas Fullkrug lashed home from inside the box with seven minutes of normal time left on the clock.
Werder Bremen striker Fullkrug, 29, only made his national team debut on the eve of the tournament, but emerged as his country's savior as Germany avoided suffering another defeat after their shock opening game loss to Japan.
Japan's own surprise defeat against Costa Rica earlier on Sunday means Group E is finely poised heading into the last round of games on Thursday.
Luis Enrique's Spain, who hammered Costa Rica 7-0 to open their campaign, top the group on four points, with Japan and Costa Rica on three, and Germany with a solitary point.
To secure passage to the last 16, the Germans must beat Costa Rica on Thursday and hope that Japan don't overcome Spain in their game.
Should Germany win and Japan draw, it would all come down to goal difference.
Germany thought they had taken the lead against Spain when Real Madrid defender Antonio Rudiger powered in a first-half header from a free-kick, but he was ruled offside following a VAR check.
Spain then struck 17 minutes into the second half as Morata raced onto a cross from Jordi Alba, deftly flicking the ball beyond Manuel Neuer in the German goal with the outside of his boot.
Fullkrug was introduced for the ineffective Thomas Muller in the 70th minute, and went on to make the difference, storming into the box and taking the ball from teammate Jamal Musiala before hammering it high beyond Unai Simon and into the far corner.
Germany have won just one of their five World Cup matches since lifting a fourth title in Brazil in 2014, but they can at least breathe a sigh of relief that their chances are still alive in Qatar - only just.