Niclas Fullkrug gave Germany a precious point against Spain as they fight for World Cup survival.
Germany's hopes of reaching the knockout phase had been given an unlikely lifeline earlier on Sunday 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.
Impressive Spain a threat
Manager Luis Enrique has pieced together an impressive blend of youth and experience as Spain seek to reclaim the World Cup crown they won in 2010.
He has the youthful brilliance of 18-year-old Gavi and Pedri, just 20, but also the old hand who has seen it all in the shape of Sergio Busquets alongside Dani Alba and the decorated Manchester City pair Aymeric Laporte and Rodri.
Gavi, the Barcelona prodigy who became the World Cup's youngest goalscorer since Pele in 1958 when he was on target in the 7-0 win against Costa Rica, was quiet here and eventually substituted but his talent is unquestioned.
Spain's slick passing was easy on the eye but when the more studied style could not find a breakthrough, Enrique was able to apply Plan B in the shape of the more direct and powerful Morata, who produced that instinctive flick for the opening goal.
They will be disappointed to concede so late and still have work to do in their final group game against Japan but there is much to admire in this Spain side.
Germany show their character
Germany might have been at a low ebb after the embarrassment of defeat by Japan in their opening game but history tells us they can never be dismissed and so it proved here in this highly entertaining game.
Flick's team had to survive that first-half scare when Neuer did superbly to turn Olmo's shot on to the bar but they dug deep after Morata put Spain ahead and were rewarded when Fullkrug, the 29-year-old latecomer to international football, put his foot through an emphatic finish.
Germany still need to beat Costa Rica on Thursday to have a chance of staying in the World Cup but there was certainly plenty here to suggest they can and it was an impressive show of character after what happened in their opening game.
They also need to hope that Japan do not beat Spain but they will be helped by the fact Enrique's team need something from that game so will not be lacking in motivation.
Player of the match
with an average of 8.17
Squad number7Player nameMorata
Squad number9Player nameGavi
Squad number21Player nameOlmo
Squad number26Player namePedri
Squad number16Player nameRodri
Squad number24Player nameLaporte
Squad number5Player nameBusquets
Squad number18Player nameAlba
Squad number11Player nameF Torres
Squad number10Player nameAsensio
Squad number23Player nameSimón
Squad number20Player nameCarvajal
Squad number8Player nameKoke
Squad number12Player nameNico Williams
Squad number14Player nameBalde
Squad number14Player nameMusiala
Squad number9Player nameFüllkrug
Squad number19Player nameSané
Squad number2Player nameRüdiger
Squad number23Player nameSchlotterbeck
Squad number21Player nameGündogan
Squad number16Player nameKlostermann
Squad number8Player nameGoretzka
Squad number6Player nameKimmich
Squad number3Player nameRaum
Squad number18Player nameHofmann
Squad number1Player nameNeuer
Squad number15Player nameSüle
Squad number10Player nameGnabry
Squad number5Player nameKehrer
Squad number13Player nameMüller
- 18AlbaSubstituted forBaldeat 82'minutes
- 9GaviSubstituted forWilliams Arthuerat 66'minutes
- 5BusquetsBooked at 44mins
- 11F TorresSubstituted forMorataat 54'minutes
- 10AsensioSubstituted forKokeat 66'minutes
- 4P Torres
- 12Williams Arthuer
- 25Ansu Fati
- 5KehrerBooked at 37minsSubstituted forKlostermannat 70'minutes
- 3RaumSubstituted forSchlotterbeckat 87'minutes
- 6KimmichBooked at 60mins
- 8GoretzkaBooked at 58mins
- 10GnabrySubstituted forHofmannat 85'minutes
- 21GündoganSubstituted forSanéat 70'minutes
- 13MüllerSubstituted forFüllkrugat 70'minutes
- 22ter Stegen
Match ends, Spain 1, Germany 1.
Second Half ends, Spain 1, Germany 1.
Corner, Germany. Conceded by Rodri.
Corner, Germany. Conceded by Daniel Carvajal.
Foul by Dani Olmo (Spain).
Niklas Süle (Germany) wins a free kick in the defensive half.
Corner, Spain. Conceded by Nico Schlotterbeck.
Substitution, Germany. Nico Schlotterbeck replaces David Raum.
Substitution, Germany. Jonas Hofmann replaces Serge Gnabry.
Goal! Spain 1, Germany 1. Niclas Füllkrug (Germany) right footed shot from the centre of the box to the top left corner. Assisted by Jamal Musiala.
Substitution, Spain. Alejandro Balde replaces Jordi Alba.
Corner, Germany. Conceded by Dani Olmo.
Attempt blocked. Joshua Kimmich (Germany) right footed shot from outside the box is blocked.
Niclas Füllkrug (Germany) wins a free kick in the attacking half.
Offside, Spain. Koke tries a through ball, but Álvaro Morata is caught offside.
Attempt missed. Niclas Füllkrug (Germany) header from the centre of the box is high and wide to the right. Assisted by David Raum with a cross following a corner.
Corner, Germany. Conceded by Rodri.
Attempt blocked. Serge Gnabry (Germany) right footed shot from the left side of the box is blocked. Assisted by David Raum.
Attempt saved. Jamal Musiala (Germany) right footed shot from the right side of the box is saved in the top centre of the goal. Assisted by Leroy Sané with a through ball.
Get your daily dose of Fifa World Cup reaction, debate & analysis with World Cup Daily on BBC Sounds