NIZHNY NOVGOROD, Russia (AP) -- Switzerland was hoping for a drama-free route into the last 16 of the World Cup. It didn't get it.
Switzerland qualified alongside Group E winner Brazil despite twice losing the lead in a riveting 2-2 draw with Costa Rica on Wednesday night.
The game ended with a stoppage-time equalizer as Costa Rican captain Bryan Ruiz's penalty kick hit the crossbar, then bounced off of goalkeeper Yann Sommer's head and into the goal. The Costa Ricans had already been eliminated from the tournament but wanted to make sure they weren't the only team to leave Russia without a goal.
Although the draw didn't affect Switzerland's progression, captain Stephan Lichtsteiner and fellow defender Fabian Schaer each picked up their second yellow cards of the tournament, meaning they will both be suspended for the knockout game against Group F winner Sweden on Tuesday in St. Petersburg.
That will leave two significant holes in Switzerland's defense as it plays for a place in the quarterfinals. Switzerland last made it to the quarters of a major tournament in 1954.
Serbia had a chance to pass Switzerland for second place with a win or draw, but Brazil dominated that match, winning 2-0. Brazil will face Group F runner-up Mexico Monday.
Switzerland twice led Costa Rica before being pegged back. The Swiss also had to survive a flurry of chances from the Costa Ricans, who kept Sommer busy all night.
The goalkeeper might have been a candidate for man of the match before the last-gasp penalty by Costa Rican captain Bryan Ruiz was scored as an own goal for Sommer after the ricochet.
Bjerim Dzemaili slammed in Switzerland's first goal from close range after being set up by a header from Breel Embolo.
Costa Rica got its first goal of the World Cup when defender Kendall Waston headed in a corner early in the second half to equalize at 1-1.
Substitute Josip Drmic put Switzerland 2-1 up in the 88th minute, and it looked like the Swiss had a victory.
But Costa Rica's Joel Campbell was hacked down in the dying minutes to give Los Ticos the chance to get one point for a draw. Ruiz took it, via Sommer's head.
Switzerland needed just a draw ahead of the game against Costa Rica and with Brazil beating Serbia 2-0, even a loss would have still seen Switzerland through.
Brazil beat Serbia with goals by Paulinho and Thiago Silva and made sure it finished top of Group E despite that slow start and a 1-1 draw with Switzerland to start group play.
KEY TO SUCCESS:
Switzerland will undoubtedly miss right back Lichtsteiner and central defender Schaer for the game against Sweden, which proved it will be a handful with a 3-0 win earlier Wednesday over Mexico.
Switzerland has the creative potential up front with the likes of Dzemaili and midfielders Xherdan Shaqiri and Granit Xhaka, but all the focus against Sweden will be how to shore up the defense.
Costa Rica was in danger of becoming the first team since Algeria and Honduras in 2010 to leave a World Cup without a goal. Waston, who plays for the Vancouver Whitecaps of Major League Soccer, made sure that didn't happen when he headed a corner home in the 56th minute.