This re-run of the 2008 final was hugely anticipated, and La Roja - champions 16 years ago - nearly broke the deadlock within 60 seconds as Pedri saw a low shot from the edge of the area saved.
Nico Williams, Lamine Yamal and Fabián Ruiz then failed to hit the target with efforts from distance, while Kai Havertz could not beat Unai Simón with a close-range header at the other end.
The striker posed the biggest goal threat for Julian Nagelsmann’s side, and he soon tested the goalkeeper again, although he was left disappointed with a tame finish after superbly bringing down a long ball.
It was Spain who finished the half strongest though, with Dani Olmo and Yamal both denied by Manuel Neuer, who ensured the opening 45 minutes ended all square.
Luis de la Fuente’s side continued to impress after the break, and Álvaro Morata should have done better when ballooning over the bar from close range.
That chance was created by Lamal, and he played a pivotal role as the deadlock was finally broken on 52 minutes, beating his man and sliding a low ball towards Olmo, who guided a low finish into the bottom corner from a central position.
Germany were dominant in the latter stages, and should have equalised when Havertz burst onto a loose ball from Simón’s goal kick, but as the ‘keeper rushed off his line to salvage the situation, the striker sent his lob over the bar.
They looked to be heading out, until Florian Wirtz brilliantly fired into the far corner from Kimmich’s knockdown in the dying seconds.
That sent the game into extra-time, which was unsurprisingly tense given the prize, a semi-final against either Portugal or France, that was at stake.
Mikel Oyarzabal flashed one terrific shot narrowly wide for Spain, and Wirtz clipped off target at the other end.
After the interval, the hosts were left baffled when a penalty check for a handball against Marc Cucurella went unpunished, while Niclas Füllkrug was unlucky with a clipped header that Simón superbly tipped around the post.
Penalties looked a near certainty, until, with just 90 seconds of extra-time remaining, Olmo clipped an inviting cross towards the penalty spot, and substitute Merino duly nodded past Neuer.
That sent Spain into the last four for the fourth time in five tournaments, although there was still time for some drama as Füllkrug headed wide in injury time, before Dani Carvajal received his marching orders for a second bookable offence.
Germany could not find an equaliser though and become the first ever host nation to lose a European Championship quarter-final.