Mikel Merino scored a dramatic header in extra time to send Spain through to the Euro 2024 semi-finals after they beat hosts Germany 2-1.
Spain took the lead through Dani Olmo six minutes into the second half, but Germany fought back and Florian Wirtz kept their hopes alive with an 89th-minute equaliser.
The match looked destined for penalties but, in the 119th minute, substitute Merino headed Spain into the final four and knocked the tournament hosts out.
Dani Carvajal was shown a second yellow card in the final seconds of the match and La Roja will now face either France or Portugal in the semi-finals.
Spain started the game brightly with a chance just seconds after kick-off when Alvaro Morata flicked the ball to Pedri on the edge of the box, but his low strike was comfortably collected by Manuel Neuer.
La Roja were then dealt a blow after Pedri was forced off the field with injury just eight minutes into the game.
Fabian Ruiz blasted a shot over the crossbar as Spain threatened on the break but, following a cautious start, Germany had their first real chance when Havertz’s header was saved by Unai Simon.
Havertz had another chance after receiving a brilliant diagonal ball from Antonio Rudiger, but Simon made a good low save and Neuer was called into action at the other end to deny substitute Olmo from distance.
Spain were straight out of the blocks in the second half when Lamine Yamal tapped the ball into Morata, who pulled off a great turn but fired over the bar.
Their quick start was rewarded in the 51st minute when Yamal hit another great low pass from the right into an unmarked Olmo, who tucked the ball into the bottom corner with a first-time effort to fire Spain ahead.
Germany searched for a response with Niclas Fullkrug and Rudiger going close before Simon made a great save to palm away Robert Andrich’s powerful effort.
Fullkrug was causing problems and had a brilliant chance after receiving the ball from Wirtz, but his effort smashed off a post.
However, Germany’s persistence paid off when Wirtz smashed a low effort into the bottom corner in the 89th minute to level the match.
Both sides had opportunities to snatch a winner in extra time when Mikel Oyarzabal hit a wide shot and Wirtz’s low effort whistled past a post.
Germany had a great chance stemming from Wirtz’s sprint down the middle, but Fullkrug dragged his shot well wide of goal and the Borussia Dortmund forward was denied again when Simon made a brilliant save to claw his header away.
Despite the host’s efforts, Merino then sent Spain through in the 119th minute, nodding into the top corner from Olmo’s cross.
The drama continued in the final minutes as Fullkrug headed narrowly wide and Carvajal was dismissed after hauling Musiala down.