Switzerland set up a World Cup last-16 tie with Sweden after a draw with Costa Rica that featured a bizarre late penalty drama.
Vladimir Petkovic's side kicked off needing just a point from their final Group E game to reach the knockout stages for the third time in four tournaments - but Serbia's 2-0 defeat by Brazil meant they would have gone through even with a defeat.
The Swiss, though, had to settle for second place in their group and just a point - despite substitute Josip Drmic putting them 2-1 ahead in the 88th minute.
Costa Rica, already eliminated, equalised in injury time, as Bryan Ruiz's penalty hit the bar and then bounced in off Swiss goalkeeper Yann Sommer's head for an own goal.
Switzerland had taken a first-half lead through Blerim Dzemaili, despite a bright start from Costa Rica, but Kendall Waston headed Los Ticos level 10 minutes into the second half from Joel Campbell's corner.
Shortly after Drmic scored, Costa Rica were awarded a penalty - only for the decision to be overturned by the video assistant referee system for an offside.
Campbell was then brought down in the box, with the penalty decision standing this time, allowing Costa Rica to equalise.
Group E winners Brazil will now face Mexico, after 2014 champions Germany failed to progress from the group stage for the first time since 1938.