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'
|Gala: No extra payment for Grosskreutz|
|Increase Bundesliga´s TV rights or be left behind - Rummenigge|
|Kane: I´m no flash in the pan|
|Perez: United showed inexperience in De Gea saga|
|Milligan: Socceroos wary of Tajikistan|
|Conte wants more players like Pelle|
|OFC World Cup Qualifying Review: Samoa to meet Tahiti in next round|
|Krychowiak stayed at Sevilla because of Emery|
|I never considered Bayern exit - Gotze|
|Balotelli ´not in good condition´, Milan must improve - Mihajlovic|
|Robben slams ´stupid´ Martins Indi|
|Robben laments injury blow|
|Euro 2016 Qualifiers Review: Bale edges Wales closer, Iceland dent Netherlands´ qualification hopes|
|De Bruyne relieved to ´boss´ Bosnia-Herzegovina|
|Blind furious after nightmare debut|
|Coleman sees shades of Charles in Bale winner|
|Conte only concerned about Italy winning|
|Mauritania v South Africa: SAFA to investigate Masilela no-show|
|AFC World Cup Qualifying Review: Qatar hit 15 in Bhutan rout|
|Belgium 3 Bosnia-Herzegovina 1: De Bruyne shines in straightforward victory|
|Cyprus 0 Wales 1: Bale winner takes Wales one step closer|
|Netherlands 0 Iceland 1: Sigurdsson winner caps difficult first game for Blind|
|Italy 1 Malta 0: Pelle spares wasteful Azzurri|
|Balotelli stars in Milan friendly win|
|Bhutan thrashed 15-0 by Qatar in qualifier|
|Rwanda v Ghana: Gyan doubt gives hosts hope|
|Tanzania v Nigeria: Enyeama out of AFCON qualifier|
|Valdes and Berahino included in Premier League squads|
|Costa Rica v Brazil: Dunga´s men return after Copa disappointment|
|Spain v Slovakia: Azpilicueta eyeing important revenge|
|Adebayor left out of Tottenham squad list for league and Europe|
|San Marino v England: Place in history books beckons for Rooney|
|Germany can cope with Reus absence - Low|
|Bayern offer aid to refugees in ´training camp´|
|BREAKING NEWS: Welbeck ruled out for months after knee surgery|
|South Korea 8 Laos 0: Son leads the way in rout|
|Australia 5 Bangladesh 0: Socceroos surge to emphatic win|
|Japan 3 Cambodia 0: Hosts pick up first qualifying win|
|Rudiger aiming to nail down Euros spot after Roma move|
|Melo happy to join Inter at last|
|Hernandez thanks Ferguson after United departure|
|Chung: AFC has compromised FIFA election|
|Wales the new best of British|
|Reus out of Germany qualifiers|
|Chile v Paraguay: Vidal missing for Copa champions|
|Ghedin: Anything is possible for Malta|
|Pogba will be worth €100m - Marotta|
|England can win Euro 2016 - Hodgson tells players|
|Conte unsure over Balotelli future|
|Portugal - France Preview: Deschamps aiming to correct mistakes|
|Martial never the same again - Mangala|
|Copa del Rey Review: Racing fall at the first|
|Shelvey dismisses talk of England snub|
|Galatasaray unable to play Grosskreutz|
|Faroe Islands v Northern Ireland: O´Neill preaches patience ahead of Euro double-header|
|Levy slams ´wholly inappropriate´ West Brom after Berahino chase|
|Panama v Uruguay: Visitors without Suarez and Cavani|
|Captaincy won´t change me - Robben|
|Liverpool sign Brazilian youngster Allan|
|PFA expects swift Berahino resolution|
|Argentina v Bolivia: Mascherano backs ´very special´ Messi|
|´I do not know if I´m worth €80million´ - Martial shocked at price-tag|
|Afellay suspension reduced|
|Noble red card rescinded|
|Portugal v France: Deschamps aiming to correct mistakes|
|Bahebeck given the all clear|
|Germany v Poland: Muller out to settle the score|
|Gibraltar v Republic of Ireland: Keane counting on McCarthy and Walters|
|Georgia v Scotland: Tbilisi trip has must-win feel for Robertson|
|Juve still the team to beat - Hernanes|
|De Gea will remain professional, says team-mate Mata|
|Berahino given extra time off following strike tweet|
|´No excuses´ as Costa seeks to kick-start season|
|I´m not like Messi or Ronaldo – Hazard|
|United States v Peru: Klinsmann out to ´prove a point´|
|Martinez unsure when Cleverley will return|
|France set for Russia friendly ahead of Euros|
|Former Manchester United forward Berbatov joins PAOK|
|De Gea must play to earn Euro 2016 spot – Del Bosque|
|Cahill thrilled to lead Socceroos|
|Wijnaldum urges patience with new-look Newcastle|
|Reid praises Stones´ professionalism|
|Mexico v Trinidad and Tobago: Islanders hoping to build on Gold Cup display|
|Choosing Brazil over Spain was easiest decision, says Rafinha|
|Galliani hails ´changed´ Balotelli|
|OFC World Cup Qualifying Review: American Samoa notch second competitive win|
|Canada v Belize: Hosts look to stay calm|
|Carragher surprised by ´big´ Martial price|
|No pressure on Rodgers - Rush|
|No Benzema, no Cavani - Arsenal ´can´t compete´ says Sol Campbell|
|FFA muzzle Postecoglou after pay dispute criticism|
|Celtic complete Simunovic signing|
|Joaquin: I´m as happy as a little boy|
|Navas given time off by Costa Rica|
|Martial unfazed by prospect of United pressure|
|Ramos urges De Gea to overcome transfer woe|