Rodrigo Moreno came off the bench to snatch a last-gasp 1-1 draw in Sweden and confirm Spain's place at Euro 2020.
Inspired saves from Robin Olsen and an injury to their own goalkeeper, David de Gea, added up to what was starting to look like a wretched outing at the Friends Arena for Robert Moreno's men.
But Rodrigo, who was dropped to the bench as his coach made six changes to the XI held by Norway last time out, reacted sharply to prod in from close range.
Sweden rode out an early storm to hit the front through Marcus Berg in the 50th minute and still have their fate in their own hands ahead of pivotal trip to Romania next month.
Sweden were indebted to Olsen during the early stages, when Spain's masterful control of possession pinned the hosts deep inside their own territory.
Each member of Spain's central midfield trio – Fabian Ruiz, Thiago Alcantara and Rodri – were denied by Olsen, although Thiago opting to try and round the goalkeeper in the eighth minute amounted to a glaring error when a square pass or a finish looked simple.
Olsen pushed a header from Spain debutant Gerard Moreno behind before Sweden belatedly found their feet - De Gea impressively saving from Robin Quaison in the 33rd minute after the Mainz striker prodded an earlier opener wide.
Those moments of encouragement proved instructive and Jan Olof Andersson's side hit the front when Berg bundled home, De Gea having completed a stunning double save from the eventual goalscorer and Emil Forsberg in vain.
Forsberg tested the Manchester United number one shortly afterwards with Spain reeling – De Gea's departure after an hour doing little to improve his country's prospects or raise optimism levels at Old Trafford ahead of Liverpool's visit on Sunday.
Gerard was increasingly feeding off scraps as a fractious contest played into Sweden's hands but glanced wide in the 67th minute. Olsen then thwarted Mikel Oyarzabal impressively, although he could do nothing when substitute Alexander Isak misjudged a headed clearance and Fabian drilled back across goal for Rodrigo to apply the finish.
Euro 2020 qualifying results on Tuesday:
At Geneva, Switzerland
Switzerland 2 (Seferovic 16, Duffy 90+3-og) Rep. Ireland 0
Gibraltar 2 (Casciaro 66, Chipolina 74) Georgia 3 (Kharaishvili 10, Kankava 21, Kvilitaia 84)
Sweden 1 (Berg 50) Spain 1 (Rodrigo 90+2)
Romania 1 (Mitrita 62) Norway 1 (Sorloth 90+2)
Faroe Islands 1 (Baldvinsson 71) Malta 0
At Beer Sheva, Israel
Israel 3 (Dabbur 16, 42, Zahavi 26) Latvia 1 (Kamess 40)
At Turku, Finland
Finland 3 (Jensen 31, Pukki 61, 88) Armenia 0
Liechtenstein 0 Italy 5 (Bernardeschi 2, Belotti 70, 90+2, Romagnoli 77, El Shaarawy 82)
Greece 2 (Pavlidis 30, Kovacevic 88-og) Bosnia and Herzegovina 1 (Gojak 35)