Didier Deschamps men have yet to fire in the tournament but must now face a buoyant Portuguese side led by Cristiano Ronaldo
The left-back has yet to feature in the tournament.
Florian Wirtz had kept their hopes alive with an 89th-minute equaliser before Merino struck in extra time.
Spain 2-1 Germany (aet): La Roja send the hosts packing from Euro 2024 after an enthralling encounter in Stuttgart