Dani Olmo hit a late stunner to spare Spain's blushes and secure a 2-1 win over Albania in a friendly that began in drab fashion but ended in high drama.
Ferran Torres tucked away a pass from substitute Yeremi Pino in the 75th minute to make the breakthrough at Espanyol's RCDE Stadium in Barcelona.
Spain were then stunned when Pau Torres headed a hopeful long ball against Albania's Myrto Uzuni and the ball trickled past debutant goalkeeper David Raya for a freak equaliser.
Yet there was still time for a classy goal from Olmo in the 90th minute, as Spain earned a victory in their first match in Catalonia for 18 years.
Ferran Torres saw an early shot hit Albania goalkeeper Etrit Berisha high on the chest and slide behind for a corner, while Pedri drew a more conventional but equally important save in the 20th minute.
The hosts threatened early in the second half when Alvaro Morata headed the ball back across goal and Pablo Sarabia sent an acrobatic volley over the bar.
Spain were almost caught cold by a rare Albania attack that produced the visitors' first shot, Keidi Bare wastefully firing too high from 15 yards when he should have tested Raya.
Goalkeeper and spectator
This was a senior debut for Brentford goalkeeper Raya and he was largely a spectator.
For large parts, the home side struggled to convert their possession into clear chances, but Yeremi took advantage of dithering defending to snatch the ball and tee up the opener with a precise throughball, Ferran Torres applying the clinical finish.
Then came the bizarre leveller in the 85th minute, with neither Pau Torres nor Raya coming out of that positively.
However, substitute Olmo produced a delicious finish to secure the home win, whipping a strike into the top right corner from 15 yards.