Mexico have escaped with a spot in a two-legged play-off to qualify for Brazil 2014, despite losing 2-1 to Costa Rica on Tuesday.
Manuel Vucetich's Mexico side looked set to miss their first World Cup finals in 24 years as Panama, their rivals for the intercontinental play-off berth against New Zealand, took a crucial lead over the United States.
But Mexico's arch-rivals, the USA, did them a favour, scoring twice in second-half injury-time to stun Panama 3-2 and ensure the loss in Costa Rica did not matter for Vucetich's team.
The results on the final matchday of CONCACAF's fourth round of World Cup qualifying saw Mexico finish with 11 points in fourth position, three clear of Panama, who would have earned the play-off berth on goals scored if they had defeated the USA.
The match at the Estadio Nacional de Costa Rica began in scrappy fashion with neither team fashioning a genuine chance on goal in the opening quarter of an hour.
But Mexico were in danger of missing out on the World Cup for the first time since 1990 and that knowledge seemed to spark the visitors, who were denied a goal in unusual circumstances after 17 minutes.
A great move through midfield saw Carlos Pena slide a pass to Oribe Peralta on the right side of the box and the striker squared the ball to Javier Hernandez, who scuffed his shot towards goal.
With Costa Rica's goalkeeper Keilor Navas stranded, Hernandez's effort rolled slowly towards the goal-line but Peralta, who was offside, looked set to slam the ball into the net before thinking better of it, letting it through his legs to nestle in the corner of the net.
Despite Peralta having not touched the ball, the referee whistled for offside.
The visitors were denied again soon after with Pena's shot blocked by a diving Costa Rica defender, before the hosts dealt Mexico a blow in the 25th minute when Bryan Ruiz slammed home the opening goal after spinning away from two defenders.
With Panama taking the lead over the USA in the other crucial CONCACAF qualifier, Mexico were in trouble but equalised quickly when Peralta thumped a loose ball into the net off the underside of the crossbar after Navas had denied Hernandez.
Mexico dominated the rest of the half but failed to convert and that lack of cutting edge came back to haunt them in the 65th minute when Cristian Gamboa's cross found Alvaro Saborio unmarked in the penalty area and the Real Salt Lake striker made no mistake with his header.
Almost immediately, Costa Rica goalkeeper Guillermo Ochoa palmed away Raul Jimenez's header as Mexico searched for another equaliser, although they seemed safe as the USA equalised in Panama.
Costa Rica then hit the post as Cristian Bolanos played a one-two with Saborio but could only dink his shot onto the woodwork and the ball bounced out.
With around seven minutes remaining, Panama moved 2-1 ahead of USA but Mexico failed to respond and were on the verge of elimination until two late goals by the Americans ensured Vucetich's team will play New Zealand in a two-legged play-off in November.
Meanwhile, Honduras confirmed their place at Brazil 2014 despite playing out a disappointing 2-2 draw at last-placed and winless Jamaica.
|Coach: J. Pinto|
for B. Ruiz 49'
for Y. Tejeda 72'
for J. Campbell 77'
|MLS: New York Red Bulls 2 Philadelphia Union 1|
|Copa Argentina Wrap: Talleres Cordoba, Defensa y Justicia advance|
|Ancelotti: Barca era not over|
|Martino unwilling to change Barca style|
|Barca confirm Alba hamstring injury|
|Ancelotti delighted with first Real trophy|
|Ki sidelined for up to two weeks|
|Pellegrini: Title race not over|
|Arsenal will drop points, insists Martinez|
|Guardiola hails Bayern fight after reaching final|
|Pulis hails battling Palace players|
|Poyet happy to avoid ´heart attack´|
|Coupe de France: Guingamp 3 Monaco 1|
|City haunted by Liverpool defeat - Pellegrini|
|Copa del Rey: Barcelona 1 Real Madrid 2|
|New MLS franchise for Atlanta|
|Del Nero elected CBF president|
|Premier League: Manchester City 2 Sunderland 2|
|Premier League: Everton 2 Crystal Palace 3|
|DFB-Pokal: Bayern Munich 5 Kaiserslautern 1|
|AFC Champions League Wrap: Pohang Steelers reach last 16|
|Krueger hopeful on Pochettino stay|
|La Liga Preview: Atletico Madrid v Elche|
|Ligue 1 Preview: Ajaccio facing relegation, Monaco aim to cut gap at top|
|Milan announce losses|
|Gradel relishing ´magical´ World Cup experience|
|Sturridge could make Norwich trip|
|Cibulkova, Mayr-Achleitner secure progression in Malaysia|
|Valencia desperate to keep Bernat|
|Lerner praises Cowans, Given|
|Championship Preview: Title glory in sight for Leicester|
|Conte talks set for end of season|
|Arrasate pens new Sociedad deal|
|Malanda to miss Wolfsburg run-in|
|Duff plans for Fulham departure|
|Buffon hails driving force Tevez|
|Garcia happy to wait on contract talks|
|Dejagah calls on fans to help with survival push|
|Kane backs Tottenham´s home-grown talent|
|No offers for Kroos, says agent|
|League One Preview: Brentford on the brink of promotion|
|Aluko admits to doubts over future|
|Hearts closer to exiting administration|
|Callejon: No regrets over Real exit|
|Blanc backed by PSG president|
|League Two Preview: Scunthorpe eye promotion while relegation battle heats up|
|Rode vows to succeed at Bayern|
|Poyet bemoans injury woes|
|Messi is mentally fatigued, says former Barca coach|
|Pellegrini has no regrets over Kompany|
|Olsson confident of fitness ahead of City test|
|Deschamps: We must proves ourselves at the World Cup|
|Milan must trust in youth, says Maldini|
|Martinez: We have that winning mentality|
|Jenkins: We need to survive and regroup|
|A-League Preview: Victory, Mariners favourites to stay alive|
|Beckham´s Miami stadium plans face opposition|
|Casillas, Real full of confidence|
|K-League Preview: Jeonnam, Jeonbuk do battle|
|CONCACAF Champions League: Cruz Azul 0 Toluca 0|
|Dortmund relieved to beat Wolfsburg|
|Arsenal sack Alfaro|
|Mineiro lose patience with tardy Anelka|
|Unfinished Sao Paulo stadium handed to Corinthians|
|Ranieri ignoring speculation|
|Giroud regaining confidence, says Wenger|
|Poyet: ´I´m not going to quit´|
|Allardyce laments costly defensive errors|
|Wenger delighted with Arsenal spirit|
|Coupe de France: Rennes 3 Angers 2|
|Football League Wrap: Barnsley off the bottom, Luton promoted|
|AFC Champions League Wrap: Guangzhou suffer shock defeat, Yokohama beat Jeonbuk|
|Premier League: Arsenal 3 West Ham 1|
|DFB-Pokal: Borussia Dortmund 2 Wolfsburg 0|
|Dyer: Bust-up claims blown out of proportion|
|Gundogan extends Dortmund contract|
|Laudrup backs Messi to shine in Copa final|
|Pellegrini: Liverpool defeat changes nothing|
|I have picked most of Italy squad - Prandelli|
|Mannone must wait for contract talks|
|Alex confident on new PSG deal|
|Wilmots signs four-year Belgium extension|
|Liverpool unites for Hillsborough anniversary|
|Nuremberg confirm Ott signing|
|Amalfitano keen on Premier League stay, says agent|
|Reinartz undergoes Achilles surgery|
|Villa suspend two backroom staff|
|Guardiola reveals Neuer doubt|
|Ancelotti urges Real to cut out errors|
|Fulham have seen the light, says Richardson|
|Chelsea interest in Costa ´normal´ - Simeone|
|Martino: Puyol could return against Real|
|Toure out for two weeks|
|Ronaldo to miss Copa del Rey final|
|Allardyce reveals Drmic scouting mission|
|Iniesta ´convinced´ of Copa del Rey success|
|Hillsborough behind emotional Gerrard reaction|
|Premier League to investigate Cardiff leak claims|
|Juve continue Scuffet praise|
|Returning players can aid survival, says Brunt|
|Martinez cools Barkley rumours|
|We do not go to Munich to swap shirts - Runjaic|
|Pulis eyes permanent deal for Ince|
|Ireland pens new Stoke deal|
|Llorente, Giovinco not getting carried away|
|Allardyce: Emirates expense behind Arsenal slump|
|Gago´s World Cup hopes hit|
|Treat Norwich like best team in the world, says Gerrard|
|Guidolin: Juventus were the better team|
|Sammer issues Bayern warning|
|Montanier warns Rennes ahead Angers clash|
|Berlusconi blocked Chelsea transfer, says Pirlo|
|Guzan: Villa desperate to reward fans|
|Anelka´s future remains unclear|
|Grobbelaar still haunted by Hillsborough disaster|
|Hecking: Wolfsburg can hurt Dortmund|
|Schuster questions Malaga´s effort|
|Paraguay Division Profesional Wrap: Libertad maintain unbeaten run|
|Inter confirm Torres interest|
|Pirlo: I thought about quitting|
|Swansea play down ´brawl´ reports|
|MLS Preview: Red Bulls, Timbers near breakthrough win|
|La Liga: Athletic Bilbao 3 Malaga 0|