Switzerland will meet Sweden in the last 16 of the World Cup as they secured safe passage from Group E with a dramatic late draw against Costa Rica.
While Costa Rica were already out having lost their opening two matches, they were the better side in Nizhny Novgorod and were good value for their 2-2 draw.
Blerim Dzemaili opened the scoring for Switzerland after they had been largely on the back-foot with Kendall Watson marking his introduction into the Costa Rica side by levelling with a second-half header.
Josip Drmic came off the bench to seemingly win it for the Swiss late on, only for a late Costa Rica equaliser coming courtesy of a Yann Sommer own goal as Bryan Ruiz's penalty went in off the Switzerland goalkeeper.
Vladimir Petkovic's side will now take on fellow Europeans Sweden in Saint Petersburg on Tuesday as Brazil's victory over Serbia ensured the five-time winners progressed as Group E winners.
Mario Gavranovic was one of two changes for Switzerland and he had an early chance to mark his start with a goal but could not making telling contact on Xherdan Shaqiri's low free-kick.
Sommer was then on hand to keep the scores level, saving a Joel Campbell strike before making a superb stop from Celso Borges' header.
Daniel Colindres was next to go close for Costa Rica, bending an effort over the goal as Switzerland struggled to contain a lively front-three in the early stages.
The lively start for Costa Rica, who topped a group containing England, Italy and Uruguay at the last World Cup, continued as Colindres hit the crossbar with another long-range effort.
Switzerland slowly worked their way into the contest and took the lead on the half-hour mark, captain Stephan Lichtsteiner's cross nodded down for Dzemaili to thrash home.
Lichtsteiner was booked later in the first half and will be suspended for the round of 16 clash against Sweden.
While Switzerland went in ahead at half-time despite being largely outplayed, they started the second period in the same lethargic way as the first.
Costa Rica finally made them pay, Campbell again going close before Kendall Watson grabbed his country's first goal of the 2018 World Cup with a well-timed header.
It was nothing more than the Central American side deserved having shown glimpses of their best form.
The equaliser at least seemed to stir the Swiss from another slumber, substitute Drmic heading against the frame of the goal as Switzerland attempted to regain their lead.
Defender Fabian Schaer joined his captain in the referee's book as Switzerland lost another member of their back-four for the Sweden game.
Switzerland retook the lead with a little over two minutes remaining as Drmic tucked away a first-time low drive.
Costa Rica thought they had been awarded a last-gasp penalty as Ruiz went down in the box but the referee's decision was nullified as VAR showed the former Fulham man was offside.
The Costa Rica skipper did get a chance to end his international career with a goal as, moments later, a legitimate penalty was given as Campbell was tripped inside the box.
There was yet more drama as Ruiz smashed the penalty against the crossbar, the ball bouncing in off Sommer to deny Ruiz a goal with his final touch but earn his country a well-deserved point.