Yann Sommer was Switzerland’s shoot-out hero as he saved Kylian Mbappe’s penalty to knock France out at the last-16 stage.
Switzerland will now go through to the quarter finals after winning 5-4 in the penalty shoot out, with extra time having finished 3-3.
Switzerland took an early 1-0 lead in the first half before Ricardo Rodriguez had the chance to double the lead at the start of the second half.
The penalty save gave France a new lease of life as Karim Benzema's two goals in two minutes put the tournament favourites back on course for the quarter final.
A wonderful curling effort from Paul Pogba looked to have put the game beyond doubt before a courageous Swiss fight with two goals in the final 10 minutes through Haris Seferovic and Mario Gavranovic took the game into extra time.
Dubbed the group of death, world champions France finished top of Group F ahead of Germany and Portugal but head coach Didier Deschamps opted for a tactical switch against Switzerland, reverting to three centre-backs.
Benjamin Pavard returned to the team while Adrien Rabiot started at left wing-back in the absence of the injured Lucas Digne.
Switzerland qualified through finishing third in Group A behind Italy and Wales and they were unchanged from their convincing win against Turkey.
France made a bright start and should have taken the lead after only two minutes but Raphael Varane headed over from Antoine Griezmann’s corner when unmarked. The Real Madrid defender should have at least hit the target.
Deschamps’ side were looking dangerous down the left, with Mbappe causing Swiss right-back Nico Elvedi problems early on, while more composure from Rabiot on a couple of occasions when in behind the defence might have caused the Swiss big problems.
But it was Switzerland who took the lead in the 15th minute when Steven Zuber clipped a cross into the box from the left and Seferovic jumped early to get above Clement Lenglet and direct his header into the bottom corner of the net.
Deschamps made a change at half-time as Kingsley Coman replaced Lenglet and Rabiot switched to left-back as France returned to a more familiar four-man defence.
A goal-saving touch from Varane prevented Breel Embolo’s driven cross from being turned in at the far post by Seferovic, before Switzerland had a golden opportunity to take a 2-0 lead with 55 minutes on the clock.
Pavard brought down Zuber with a mindless sliding challenge but the referee had to be persuaded to go and look at the pitchside monitor after allowing play to continue before awarding the spot-kick.
When he did, Lloris saved Rodriguez’s effort with a strong right hand down to his right-hand side.
It proved the game’s turning point as four minutes later Switzerland found themselves behind.
First, Benzema controlled Mbappe’s pass with a great touch even though the ball was slightly behind him, before clipping a delicate finish over the advancing goalkeeper.
Then, in the 59th minute, Benzema scored his second goal to turn the game on its head. Yann Sommer saved Griezmann’s shot from a tight angle but the ball looped up to the far post where Benzema headed it in from close range.
Pogba looked to have put the seal on it with 15 minutes remaining with a superb effort from 25 yards out, curling the ball into the top corner of the net, but Seferovic headed his second goal of the game in the 81st minute to set up a more tense finale than France had anticipated.
Switzerland thought they had equalised two minutes later when Gavranovic controlled Rodriguez’s shot and poked the ball past Lloris, but the flag was correctly up for offside.
However, Gavranovic was not to be denied and struck in the final minute to level things up, reaching Granit Xhaka’s defence-splitting pass through the middle and beating Lloris with a low shot from the edge of the area.
Coman crashed a shot against the crossbar right at the death but the game went to extra time.
Sommer made a fine save to deny Pavard in the first half of extra time while Mbappe scuffed an effort into the side-netting from four yards out after the break when it looked like he was certain to score.
Sommer also plucked an Olivier Giroud header from the top corner in the final minute of extra time as the match went to penalties.
Manuel Akanji, Gavranovic, Fabian Schar, Ruben Vargas and Admir Mehmedi all scored for the Swiss in the shoot-out but Mbappe was unable to follow successful spot-kicks from team-mates Pogba, Giroud, Marcus Thuram and Presnel Kimpembe as Sommer pushed away his effort.
It has been the second game of the day to end in a dramatic finish after Spain beat Croatia 5-3 following another round of extra time in Copenhagen.