Switzerland's hero of the previous round when they knocked out world champions France in similar fashion was on top form again during 120 minutes and although he saved one in a dramatic conclusion his side missed three out of four spot-kicks.
There was huge relief for Spain, into their first semi-final since 2012 when they won their second successive European Championship, having wasted a host of chances.
After scoring five in their last two matches Luis Enrique's side retreated into their shell somewhat with a much more circumspect performance and despite the advantage of Denis Zakaria's own goal they did not really press hard until extra-time.
That was forced by Xherdan Shaqiri's 68th-minute goal to make it 1-1 but after Remo Freuler's harsh red card the Swiss had no option but to see out the game and hope for the best in a shootout.
Sergio Busquets hit a post and Rodri's effort was saved by Sommer but Dani Olmo and Gerard Moreno scored and with Fabian Schar, Manuel Akanji and Ruben Vargas all failing it left Mikel Oyarzabal to send Spain through.
Ominously, each time Spain have progressed past the quarter-finals they have gone on to lift the trophy but if they are to add to their three titles they will need to be sharper up front against either Italy or Belgium in the last four at Wembley.
It was a tough result for Switzerland, who had kept their opponents at bay largely thanks to their committed organisation and also Sommer.
Suspended captain Granit Xhaka's replacement Zakaria did not have the impact he would have wanted as it was his outstretched leg which gave Spain the lead from their first shot on target in only the eighth minute.
Koke's outswinging corner cleared the penalty area and dropped to Jordi Alba 25 yards out and his first-time strike took a huge deflection off the Borussia Munchengladbach midfielder to completely wrongfoot goalkeeper Yann Sommer.
After Breel Embolo limped off with a hamstring injury Switzerland should have gone 2-0 down but Cesar Azpilicueta headed straight at Sommer.
But having recovered from those two setbacks the Swiss regrouped, reorganised and started to look more of a threat - particularly aerially, as they had against France.
Akanji, twice, and fellow defender Silvan Widmer failed to make the most of headers from Shaqiri corners either side of half-time and so the Liverpool forward took matters into his own hands from the next set-piece.
Having spotted Unai Simon had left his near post free, Shaqiri whipped in an ambitious attempt but only found the side-netting.
Moreno replaced the ineffective Alvaro Morata as Enrique sought to regain the initiative but it was Switzerland who continued to build pressure only to waste set-pieces with Zakaria the next to head narrowly wide.
Spain's response saw Ferran Torres' flying volley deflected behind by Haris Seferovic, who would have been hoping to have had influential touches in the other penalty area but was starved of opportunities.
Steven Zuber was denied by Simon at close range but it was Shaqiri, Switzerland's most creative player, who eventually got them back on level terms thanks to a large helping hand from the opposition centre-backs.
Aymeric Laporte and Pau Torres got in each other's way and the ball bounced kindly to Freuler who squared for Shaqiri to sweep home and become his country's leading scorer at the European Championships with four goals.
But Freuler immediately made things more difficult when he was dismissed for a sliding tackle on Moreno and the loss of Shaqiri to an apparent knee injury lessened their chances further.
However, Spain's inability to pose a threat made extra time inevitable and penalties almost as likely and Moreno squandering three good chances early in the first added period confirmed as much.
Sommer, who played his part with a good save from Oyarzabal, had saved the decisive kick from Kylian Mbappe on Monday and, although he denied Rodri, of his four team-mates who were successful from the spot against France only Mario Gavranovic was on target.