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.
Job done for Moreno in campaign hit by tragedy
As has frequently been the case over recent years, this was not Spain at their fluent best. But Moreno can reflect on mission complete in a job that came to him in tragic circumstances following Luis Enrique's decision to step down.