Switzerland drew 2-2 with Costa Rica on Wednesday to set up a World Cup round-of-16 clash against Sweden, with the Swiss qualifying in second place in group E behind Brazil, who beat Serbia 2-0 in Moscow.
Blerim Dzemaili put the Swiss ahead on 31 minutes in Nizhny Novgorod before Kendall Waston equalized on 56 minutes with Costa Rica's first goal of the finals. Josip Drmic put the Swiss 2-1 up, but an injury-time penalty by Bryan Ruiz hit the bar and bounced in off Swiss keeper Yann Sommer to secure a point for the Central Americans.
The Swiss will now face Sweden, who topped group F following Germany's shock exit from the tournament at the hands of South Korea.
But they must do so without captain Stephan Lichtsteiner and defender Fabian Schaer, whose second bookings of the competition earned them each a one-match suspension. Costa Rica, meanwhile, avoided unwanted history as the only team not to score at the 2018 finals.
The trio that were fined for their Albanian-eagle gestures against Serbia - Granit Xhaka, Xherdan Shaqiri and Stephan Lichtsteiner - started on a cool summer's evening in the Nizhny Novgorod Stadium.
Mario Gavranovic replaced Haris Seferovic up front as expected, with Breel Embolo replacing the ill Steven Zuber, the only other change from the Serbia game.
Costa Rica made three changes from the line-up that lost 3-0 to Brazil, with Oscar Ramirez starting Joel Campbell up front in place of Marcos Urena.
The Swiss fans in Nizhny Novgorod were keen for Germany to qualify so that Switzerland could play them in the second round.
But there would have been more than a few schadenfreude-laden Swiss voices joining the cheers that came from the pubs on the banks of the Volga as South Korea's two late goals dumped Germany out.
They knew that their team needed just a draw against Costa Rica to qualify, but that only a win could see them top the group.
Coach Vladimir Petkovic had talked before the game about the "organized chaos" that Shaqiri brings to proceedings and that was evident in the 4th minute as the Stoke City man nutmegged a defender and set up Gavranovic, who fluffed the chance.
But Costa Rica were desperate to avoid being the only team at the World Cup not to score and they began to pepper Yann Sommer's goal. The keeper did well to tip Celso Borges' header onto the post in the 6th minute before saving well from Campbell.
Daniel Colindres then cracked the bar with a curling shot from the edge of the box in the 10th minute before Sommer had another finger-tip save from a Bryan Oviedo shot on 19 minutes.
And then, just as they had done against Serbia, Switzerland recovered from their sluggish start. A cross from Lichtsteiner was headed down by Embolo and smashed home by Dzemaili to make it 1-0 on 31 minutes.
At half-time, the teams headed down the tunnel to the news that Brazil were 1-0 up against Serbia.
After an insipid opening to the second half, the stadium came alive on 60 minutes, with the Costa Rica fans nearly tearing the roof off as Kendall Waston gave them the goal they'd craved.
Campbell's corner was headed in by the big Vancouver Whitecaps defender after he looked to have shoved Switzerland's Manuel Akanji, but the video assistant referee was not deployed.
From a Swiss perspective, the tension was taken out of the game near the 70-minute mark by the news that Brazil had scored a second in Moscow, with a Brazil win meaning that Switzerland could lose to Costa Rica and still qualify.
On 78 minutes, Swiss substitute Josip Drmic headed against the bar before he looked to have won it for his team on 88 minutes after side-footing home a low cross.
But referee Clement Turpin awarded Costa Rica a stoppage-time penalty after a foul by Denis Zakaria on Campbell and their fans had another goal to cheer after Ruiz's kick went in via first the bar, then Sommer, with FIFA awarding an own goal against the keeper.
After so much speculation that the Swiss would face Costa Rica minus key men due to suspension, they will now have to do so against Sweden, with Lichtsteiner and Schaer serving their one-match suspensions against the Scandinavians.