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'
|Bruce rues calamitous Huddlestone miss|
|UEFA Europa League Review: Torino mark return with big win, Lyon victorious|
|Southampton win again|
|Jenkinson agrees West Ham loan|
|Tottenham agree Dier move|
|Rincon seals Genoa move|
|Dunne announces international retirement|
|Romulo close to Juve switch|
|Trencin 0 Hull City 0: Huddlestone pays penalty in Hull stalemate|
|Rennes prise Prcic away from Sochaux|
|CSL Preview: Liaoning look for swift response, buoyant R&F visit Henan|
|Pique desperate to regain high standards|
|Marseille agree three-year Stade Velodrome lease|
|Torres will not be leaving, says Mourinho|
|Bastia bring in Brandao|
|Paris Saint-Germain v Guingamp: League and cup winners battle for Trophee des Champions|
|Argentine Primera Division suspended after Grondona death|
|Immobile: Lewandowski is the past, I am the future|
|Rose pens new Tottenham deal|
|CSL Review: Evergrande end Harbin run, Henan edge clear of danger|
|Ivory Coast appoint Renard|
|Three-man shortlist for South Korea post|
|MLS Preview: Sounders aiming to bounce back against Earthquakes|
|Personal reasons behind Evra´s Juve switch|
|Liga MX Preview: Monterrey out to continue winning run|
|J.League Preview: Oenoki begins S-Pulse reign at Tokyo|
|K.League Preview: Jeonbuk face tricky Jeonnam test, Pohang visit Suwon|
|Kakuta loaned to Vallecano|
|Morrison remanded in custody|
|Hernandez coy on United exit|
|Neymar on road to recovery|
|Feyenoord capture Wilkshire and Basacikoglu|
|Yoel makes Valencia switch|
|Heaton extends Burnley deal|
|Lees leaves Leeds for Wednesday|
|Caballero eyes first-team action|
|Newcastle ´monitoring´ Remy, claims Pardew|
|Rodriguez ready to fight for Real place|
|Cavani ´certain´ he will stay with PSG|
|Morrison charged with assaults|
|Copenhagen slam security after fan violence in Kiev|
|Gerrard: Suarez ´too good´ for Arsenal|
|Mourinho explains Lukaku exit|
|Simeone content with Atleti workout|
|Milligan: Australia targeting Asian Cup|
|Ronaldinho rules out retirement|
|Rodgers challenges Henderson|
|Jovetic can be City catalyst - Pellegrini|
|Janko joins Sydney as marquee|
|Deila ´unbelievably disappointed´ with Celtic|
|MLS Review: DC close on Sporting, Red Bulls hold RSL|
|Ecuadorian Primera A Review: Emelec crowned champions|
|Bolivar 1 San Lorenzo 0 (agg 1-5): Visitors advance to maiden Libertadores final|
|Gerrard open to move abroad|
|Lukaku tells Chelsea ´no hard feelings´|
|Zaha eager to impress Van Gaal|
|Liverpool down Man City after shoot-out|
|Atletico fall to Gonzalez´s penalty heroics|
|Glazers offer up 8m United shares|
|Bertrand joins Southampton on loan|
|Van Aanholt features as Sunderland fall to defeat|
|UEFA Champions League Review: Celtic hammered in Warsaw|
|Collison stakes his claim as QPR are held|
|Newcastle youngsters edge to Wednesday win|
|Villa beaten by buoyant Chesterfield|
|Juve held by new boys Cesena|
|Late Drinkwater strike helps Leicester see off Walsall|
|Everton seal club-record Lukaku deal|
|Lazio complete De Vrij capture|
|Fabregas opens account in Chelsea win|
|AFA president Grondona dies aged 82|
|Trezeguet heading for Indian Super League|
|Premier League to introduce vanishing foam|
|Rennes bring in Bruls|
|Kehl steps down as Dortmund captain|
|Capello: I´m staying until 2018|
|Pedro saddened by Fabregas departure|
|Fernandez agrees Porto switch|
|West Ham close on Jenkinson, says Allardyce|
|Donnelly out for three months|
|Chambers: It has been a whirlwind|
|Lukaku drops Chelsea exit hint|
|Mee signs new deal at Burnley|
|Lovren denied United States visa|
|Redknapp admits Fer interest|
|No official Cuadrado bids, insists agent|
|Maguire ready to make step up|
|Rodgers: Liverpool have a strategy in transfer market|
|Ki out to prove himself at Swansea|
|Garcia plays down importance of Real scalp|
|Evian complete Bruno signing|
|Poyet frustrated by lack of new faces|
|Mexes convinced Milan are improving|
|Mazzarri praises Inter attitude|
|Ronaldo could face Manchester United - Ancelotti|
|Tevez thanks fans after father found ´safe and well´|
|Gabi braced to tackle big-spending rivals|
|Shaw: I deserved Van Gaal criticism|
|Morinigo surprised by Gedoz substitution|
|Honduras appoint Medford|
|Van Gaal delighted with United display|
|Roma battle past Real Madrid|
|Simeone talks up Hernandez transfer|
|Defensor Sporting 1 Nacional Asuncion 0 (1-2 agg): Visitors into final despite loss|
|United edge Inter on penalties|
|Gerrard: It´s been ´the worst three months of my life´|
|Sabella set to quit Argentina post|
|Toure plans to see out career with City|
|Tevez´s father released after kidnapping|