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'
|I´m glad Rochdale haven´t made the news - Hughes|
|Getafe 2 Celta Vigo 1: Hosts come from behind for first win in 10|
|Real hit back at media reports over transfer dealings|
|Rochdale 1 Stoke City 4: Joy and angst for Bojan as Premier League side progress|
|Turkish Super Lig Review: Kuyt at the double in Fenerbahce win, Besiktas back on track|
|Senegal v Algeria: Morale is high, insists Gourcuff|
|Cassano leaves beleaguered Parma|
|Copa del Rey Preview: Atleti look to overturn Barca advantage, Espanyol wary|
|Atletico Madrid v Barcelona: Griezmann targets second-leg fightback|
|Sheffield United v Tottenham: Clough expects fired-up Spurs for second leg|
|Cape Verde 0 Zambia 0: Stalemate sends both sides out|
|Democratic Republic of Congo 1 Tunisia 1: Both teams qualify for quarter-finals|
|FA Cup fifth round: Middlesbrough handed Arsenal test|
|South Africa v Ghana: Must-win game for Mashaba´s men|
|Parma v Juventus: Serie A leaders strong favourites to reach semi-finals|
|Van Praag planning to stand for FIFA presidency|
|Inter snap up Brozovic|
|Van Persie unsure of long-term United future|
|Broken metatarsal rules El Shaarawy out for at least six weeks|
|FIFA: No disciplinary proceedings against Real|
|No Plan B if Guardiola goes - Rummenigge|
|Millwall take Hooiveld on loan|
|Chile v United States: Klinsmann has high hopes for young stars|
|Carver to lead Newcastle until end of season|
|Shenaishil taking positives from last-four exit|
|Neymar happy with life at Barca and Messi relationship|
|Lucas Silva ready for life at Real|
|Milan ´always with Inzaghi´ - Menez|
|Rodriguez living the dream at Real|
|Stielike expecting Australia in final|
|Mourinho not dwelling on Bradford defeat|
|Schweinsteiger under no pressure to extend Bayern contract|
|Herd heads to Wigan on loan|
|Inter defensive duo suffer hamstring tears|
|UAE coach Ali eyes Asian Cup final|
|Gattuso dreaming of managing Rangers|
|Fiorentina agree return of Gilardino on loan|
|Sakho hits back at critics|
|South Korea 2 Iraq 0: Kim books sixth Asian Cup final place|
|Sturridge could return against Chelsea|
|Zinnbauer backs Drobny as Hamburg first choice|
|Drogba targeting Chelsea stay|
|Postecoglou confident Australia squad can progress|
|UEFA does not have the courage to run against me - Blatter|
|Foster: Anichebe unplayable|
|Australia v UAE: Japan´s absence a boon for Asian Cup hosts|
|Milan v Lazio: Injury-hit visitors aiming for back-to-back wins|
|Trezeguet confirms retirement|
|No ´major problems´ with Nicolas Frey´s head wound|
|Strootman injury not "serious" - Garcia|
|No Paraguay, USA for retiring Riquelme|
|Saint-Etienne did not try to play football - Blanc|
|Primeira Liga Review: Sporting move within one point of Porto|
|La Liga Review: Parejo downs Sevilla, Resino starts with a point|
|Serie A Review: Juve go seven points clear as Roma draw again|
|Ligue 1 Review: Paris Saint-Germain and Lyon make Marseille pay for slip-up|
|Burkina Faso coach puts AFCON exit down to bad luck|
|Saint-Etienne 0 Paris Saint-Germain 1: Ibrahimovic scores in repeat performance|
|Shenaishil optimistic despite Kasim absence|
|Walcott: Goal has been a long time coming|
|DR Congo v Tunisia: Leekens warns against complacency|
|Congo 2 Burkina Faso 1: Thievy helps send 2013 runners-up crashing out|
|Gabon 0 Equatorial Guinea 2: Balboa and Iban put hosts through|
|McCarthy and Distin on road to recovery|
|Gil has hit the ground running - Lambert|
|Eredivisie Review: Ajax and Feyenoord lose ground after dour draw, Eagles secure big win|
|Wenger confirms Gabriel move is imminent|
|Eto´o presented to Sampdoria fans|
|Cape Verde v Zambia: Victory a must for 2012 winners to avoid elimination|
|Brighton and Hove Albion 2 Arsenal 3: Walcott and Ozil among the goals for holders|
|Mancini upbeat despite ´cruel´ late defeat|
|Pogba revelling in rich vein of form|
|Aston Villa 2 Bournemouth 1: Gil helps under-fire Lambert breathe easy|
|Defour dismissed after Standard Liege banner taunt|
|Allardyce relieved with scrappy West Ham win|
|Sturridge ´happy man´ after return to Liverpool training|
|Inter 0 Torino 1: Moretti ends unbeaten run for top-four hopefuls|
|Juventus 2 Chievo 0: Pogba inspires victory as leaders march on|
|Bristol City 0 West Ham 1: Super sub Sakho sinks City|
|Hughes in talks over new Stoke deal|
|Delph signs new contract|
|Chelsea v Liverpool: Mourinho demands League Cup response|
|Football League Preview: Derby eye top two, Cambridge back to reality|
|Nani not giving up on Old Trafford career|
|Perth Glory 3 Melbourne Victory 3: Leaders stage two-goal late comeback|
|Neymar: Barca have no interest in Real results|
|Milan defender Mexes apologises for red card|
|South Korea v Iraq: Strange lead-up for Shenaishil´s men|
|Lazio´s Djordjevic thanks well-wishers ahead of ankle surgery|
|Iran´s Asian Cup appeal dismissed by AFC|
|Cech urges Chelsea to clean up FA Cup exit ´mess´|
|Henderson: Liverpool are up for the cup|
|Edimar wants ´normal´ ban for Real star Ronaldo|
|Pellegrini defends misfiring City strikers|
|Australia ready for UAE - Sainsbury|
|Blanc takes positives from past|
|Inzaghi promises ´something different´ at Milan|
|Mexes sorry for seeing red|
|La Liga Review: Wins for top three|
|Vitoria Guimaraes 2 Gil Vicente 2: Last-gasp penalty salvages point for hosts|