A Mikel Merino goal in the final minute of extra time took Spain to a 2-1 win over Germany and into the Euro 2024 semi-finals.
After a fiery yet goalless first half, Spain's Dani Olmo latched onto an inch-perfect pass from Spanish wunderkind Lamine Yamal to give La Roja the lead on 51 minutes.
Niclas Fuellkrug struck the post with 14 minutes remaining but with the hosts staring at an early exit, Florian Wirtz slammed in a Joshua Kimmich knock-down in the 89th minute to take the game to extra time.
With a minute remaining in extra time and the game looking set for penalties, Olmo lofted a cross for Merino, who headed Spain into the semi-finals and on course for a record-breaking fourth Euros crown.
Germany's exit brings to an end the hosts' hope of a summer fairytale Euros victory after a decade of poor performances at major tournaments, while also lowering the curtain on Toni Kroos' stellar career.
The battle between the two most successful Euros nations, with three titles apiece, was billed as a final come early, with the in-form Spaniards against Nagelsmann's reborn hosts.
Spain nominated Kroos as Germany's most dangerous pre-match but the midfielder had a huge, even if unintended impact early, colliding with Pedri, who was then subbed off with a leg injury for Olmo.
Germany, with the oldest squad at Euro 2024, struggled with Spain's speed during the first half, frequently coming into duels a fraction too late, but the two best chances of the opening half fell to the hosts -- and both to Kai Havertz.
The Arsenal forward leapt highest to head a cross directly at Unai Simon early and then scuffed a tame shot at the goalie later in the half with just the 'keeper to beat.
After a goalless first half, Nagelsmann took off surprise starter Emre Can for the pink-haired Robert Andrich, while the ineffective Leroy Sane was hooked in place of Wirtz.
The substitution who would make his mark however was Olmo, who gave Spain the lead six minutes into the second half, slicing through the sleepy Germany defence to perfectly place a Yamal pass past Manuel Neuer in the bottom left corner.
The goal kicked Germany into gear with Wirtz particularly dangerous.
The Bayer Leverkusen starlet linked with Fuellkrug on the counter with a quarter of an hour remaining but the striker, under heavy attention from the Spanish defence, could only hit the post.
With 10 minutes remaining Nagelsmann made his final substitution, bringing veteran Thomas Mueller from the bench.
But it was Wirtz -- 13 years his junior - who made the difference, skimming a Joshua Kimmich header across the grass and in at the far post in the final minute, sending the game to extra time.
Mikel Oyarzabal, on for Williams, curled a 104th-minute shot just wide of the post and Wirtz did the same a minute later with the goal beckoning.
Germany appealed strongly for a penalty in the second period of extra time, after a goal-bound Jamal Musiala shot clearly connected with Marc Cucurella's outstretched hand.
After the penalty drama, Olmo curled in a cross for Merino, who leapt high to head the ball past Neuer and put Spain into the Euros semi-finals.
AFP