Niclas Fullkrug earned Germany a vital point against Spain as they battled for World Cup survival on Sunday.
Germany's hopes of reaching the knockout phase had been given an unlikely lifeline when Costa Rica beat Japan when any other result would have meant defeat by Spain would send them out.
Hansi Flick's side still need to defeat Costa Rica in their final Group E game and hope Japan do not spring a shock against Spain but at least they know their hopes of moving into the last 16 are intact after falling behind at Al Bayt Stadium.
Spain, who almost went ahead in the first half when keeper Manuel Neuer turned Dani Olmo's shot on to the bar, took the lead after 62 minutes when substitute Alvaro Morata applied a brilliant near-post flick to Jordi Alba's cross.
Germany pressed forward and Fullkrug gave them a point seven minutes from the end when he burst through and lashed an unstoppable finish high past Spain keeper Unai Simon.
Leroy Sane almost won it for Germany in the dying seconds but ran out of space as he raced through on goal and the ball was scrambled clear.