The Swiss had been seconds away from elimination during 90 minutes but go through to face Spain after progressing from a major tournament knockout game for the first time since 1938.
Haris Seferovic headed the Swiss ahead and they had a penalty saved that could have made it 2-0 before Karim Benzema scored twice and Paul Pogba put France 3-1 up with a screamer.
Seferovic headed in his second goal of the game for Switzerland and substitute Mario Gavranovic hammered in a last-minute equaliser to send the game to extra time.
Mbappe missed a couple of big chances for the world champions in extra time and Olivier Giroud had a header saved in the final minute.
Paris St-Germain forward Mbappe was the only player to fail to score in the shootout, after an excellent Yann Sommer save.
Switzerland play Spain, who also came through a thriller – 5-3 after extra time against Croatia – in the quarter-final in St Petersburg on Friday.
This is the biggest shock of Euro 2020 so far, with world champions France having been tipped to win the tournament by 12 of 15 BBC pundits before it started.
Switzerland’s finest hour?
The last time Switzerland were in the quarter-finals of a major tournament was the 1954 World Cup that they hosted.
They had not progressed through a knockout game since the 1938 World Cup.
It could all have been so different as they faced elimination in the group stage after picking up one point from their opening two games.
Manager Vladimir Petkovic wrote an open letter in a Swiss newspaper apologising to fans and asking them to back the team against Turkey. They won that game and reached the last 16 as one of the best third-placed teams.
Petkovic’s side fully deserved their half-time lead against France thanks to Seferovic’s header from a cross by Zuber, his fourth assist of Euro 2020. That was the first time Switzeland have ever taken the lead in a competitive game against France.
They missed a glorious chance to go 2-0 up when Zuber was chopped down by Benjamin Pavard and a penalty was given by the VAR, but Ricardo Rodriguez’s weak kick was well saved by Hugo Lloris.
Four minutes and three seconds later they trailed through a Benzema double and it looked all over when Pogba scored.
But just as Croatia did against Spain earlier in the day, Switzerland scored twice in the final 10 minutes to force extra time.
Seferovic headed in for his third goal of the tournament and Gavranovic latched on to Granit Xhaka’s perfect pass to score in the 90th minute.
They had few chances to score in extra time but they tucked away all five penalties in the shootout to progress to Friday’s quarter-final in Russia.
France fail to take advantage of comeback
France were wretched in the first half as Didier Deschamps tried a three-man defence – a system he barely ever uses – because of injuries to two of their left-backs.
He abandoned that midway through the first half with Les Bleus trailing 1-0 and in danger of going behind by more.
It looked as if 243 seconds in the second half was their get-out-of-jail-free card. That was the time between Lloris’ penalty save at 1-0 and Benzema putting them 2-1 up.
Benzema’s first was sensational, as he controlled Mbappe’s pass with a backheel flick before clipping the ball past Sommer.
He then headed in at the back post from Antoine Griezmann’s deflected cross.
Pogba scored one of the goals of the tournament as he found the top corner from 30 yards out.
They looked completely comfortable then – but bottled it as the Swiss came back. Kingsley Coman did almost win it for them with the last kick of the 90 minutes but hit the crossbar.
And so it came to penalties and Mbappe – one of the stars of France’s World Cup win – ended Euro 2020 with no goals and the penalty miss that eliminated them.
They never got going in the Euros – and now the only place they are going is home.