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'
|Baines is not for sale, repeats Martinez|
|Suche nach AVB-Nachfolger: Van Gaal zu Tottenham?|
|Wenger ´surprised´ by Cole omission|
|A-League Wrap: Wellington win at last, Perth held by Adelaide|
|Muller: It will be tough to match 2013 success|
|Arsenal have the necessary belief, says Mourinho|
|Cagliari players free to go, says club president|
|Pellegrini pinpoints Suarez threat|
|Simeone ´satisfied´ by Atletico´s form|
|Benitez unhappy with ´horrible´ pitch|
|Guardiola hails Bayern´s ´massive´ year|
|Wenger wants UEFA to abolish away-goal rule|
|La Liga Wrap: Atletico boost title hopes, Sevilla beat Villarreal|
|Ligue 1 Wrap: Saint-Etienne leapfrog Nantes, Reims hammer Ajaccio|
|Primeira Liga Wrap: Sporting miss chance, Vitoria Guimaraes win|
|Serie A Wrap: Napoli held, Udinese win|
|Eredivisie Wrap: Vitesse miss chance to extend lead|
|FIFA Club World Cup: Bayern Munich 2 Raja Casablanca 0|
|Scottish Premiership Wrap: Celtic extend lead as Inverness slip up|
|Bundesliga Wrap: Dortmund, Leverkusen both beaten|
|League One Wrap: Brentford take advantage as top two stutter|
|League Two Wrap: Boothroyd sacked as Northampton lose, Oxford held|
|Downing delights in late leveller|
|Hughes happy with Adam impact|
|Meulensteen: Fulham need to turn performances into points|
|Lambert upbeat despite defeat|
|Bruce vents frustration|
|Hughton backs referee over Brown decision|
|Poyet worried that time is running out for Sunderland|
|Allardyce bemoans defensive errors against United|
|Pulis hopes Palace learn lessons|
|Pellegrini praises Navas and Milner impact|
|Pardew praises ´dream-like´ Newcastle victory|
|Championship Wrap: Leicester defeat QPR, Burnley go top|
|We must rebuild, says Klopp|
|Moyes defends Januzaj dive|
|Premier League Preview: Arsenal v Chelsea|
|Premier League: West Brom 1 Hull City 1|
|Premier League: Sunderland 0 Norwich City 0|
|Premier League: Crystal Palace 0 Newcastle United 3|
|Premier League: Stoke City 2 Aston Villa 1|
|Premier League: Manchester United 3 West Ham 1|
|Premier League: Fulham 2 Manchester City 4|
|Bundesliga: Borussia Dortmund 1 Hertha Berlin 2|
|Martino happy at Barcelona|
|Ancelotti restates desire to keep Alonso|
|Rodgers lauds Suarez|
|Mackay: I´m going nowhere|
|Premier League: Liverpool 3 Cardiff City 1|
|Walker expects ´difficult´ Southampton test|
|Acerbi suffers cancer relapse|
|A-League: Melbourne Heart 1 Melbourne Victory 3|
|De Boer dismisses Spurs link|
|Mourinho: It´s not me against Wenger|
|Pellegrini targets trophies|
|Conte would welcome Italy opportunity|
|Lahm calls for Bayern focus|
|Bale: I am under less pressure at Real|
|Ranieri laments missed opportunities|
|Moyes confirms Fellaini back scan plan|
|Bayern Munich will respect Raja Casablanca, says Guardiola|
|Yeboah signs for Monchengladbach|
|Proud Benitez demands focus|
|Serie A Preview: Atalanta v Juventus|
|Primeira Liga Wrap: Porto, Benfica victorious|
|Football League Wrap: Tranmere defeated, Chesterfield move top of League Two|
|Serie A Preview: Inter v Milan|
|Bundesliga: Frankfurt 1 Augsburg 1|
|Ligue 1: Monaco 1 Valenciennes 2|
|La Liga: Elche 0 Malaga 1|
|Eredivisie: RKC Waalwijk 1 Twente 1|
|La Liga Preview: Getafe v Barcelona|
|Ligue 1 Preview: Paris Saint-Germain v Lille|
|UAE Pro League Wrap: Al Ahli extend lead, Al Shaab earn rare win|
|Lambert seeks more Villa away success|
|Sunderland will have ´no excuses´ for Norwich failure, says Poyet|
|Hughton hails Poyet impact|
|Pardew anticipating difficult Palace clash|
|UEFA provisionally ban three clubs from European competition|
|La Liga Preview: Valencia v Real Madrid|
|Valdes to keep new club quiet|
|Allardyce urges West Ham to expose United frailties|
|Bruce bemoans Brady injury|
|Laudrup rules out Tottenham switch|
|Premier League Preview: Swansea City v Everton|
|Benitez is ´a lucky charm´, says De Laurentiis|
|Stoke wait on Shawcross fitness|
|Koscielny to miss out on Chelsea clash|
|Liverpool owner hails Suarez deal as sign of club´s progress|
|Moyes reveals Nani setback|
|Schweinsteiger to return in January|
|Thohir not worried ahead of derby|
|Mourinho eyes defensive improvements|
|Pellegrini optimistic on Zabaleta return|
|Gourcuff reveals contract refusal|
|Suarez pens new long-term Liverpool deal|
|Klopp predicts tough Hertha battle|
|Dempsey has medical ahead of Fulham return|
|Bruce sympathetic to Mackay situation|
|A-League: Brisbane Roar 0 Newcastle Jets 2|
|Celtic´s Lustig set to miss four months|
|Messi blasts Barca official|
|Redknapp slams Villas-Boas´ signings|
|Atalanta out to continue home record|
|Phillips poised for January Palace exit|
|Dembele: Spurs ´positive´ about Sherwood appointment|
|Benitez predicts busy January at Napoli|
|Kerslake expects Mackay to be in charge for Liverpool game|
|Lowe given Glory role|
|Baines set for Everton return|
|Pedro keen on emulating Iniesta|
|Pochettino not interested in January purchases|
|Poyet calls for mid-season break|
|Iajour up for Bayern test|
|Martinez seeking ´short-term solutions´ in transfer window|
|Kompany urges City to remain focused|
|Rodgers glad he avoided Tottenham|
|Del Piero in line to take on Juventus in Australia|