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'
|Gerrard, Keane and Bradley pull out of MLS All-Star squad|
|Marseille reach Diaby agreement|
|Sammer thrilled with Vidal´s winning mentality|
|Platini expected to launch FIFA presidency bid|
|Romanov sacked me over Barca snub - Korobochka|
|Villa complete Crespo capture|
|Wolfsberger v Borussia Dortmund: Bender praises ´fun but exhausting´ training|
|Okaka swaps Sampdoria for Anderlecht|
|Southampton v Vitesse: Fonte excited for ´dream´ sojourn into Europe|
|Bournemouth agree King compensation|
|West Ham v Astra: Kouyate confident West Ham can progress|
|Vidal completes Bayern switch, signs four-year deal|
|Fabregas calls for Champions League improvement|
|BREAKING NEWS: Filipe Luis completes Atletico return|
|Bayern to present Vidal|
|Wenger unfazed by Mourinho´s spending jibe|
|Pellegrini: Sterling will justify price tag|
|Cavani hit with two-match Uruguay ban|
|Bonucci to remain at Juve until 2020|
|No bids for Berahino - West Brom|
|Putin: Blatter deserves a Nobel prize|
|Howe: Swansea a benchmark for Bournemouth|
|New Parma to play in Serie D|
|Mata vows to hit the goal trail at United|
|Drogba ´perfect fit´ for Montreal|
|Berahino ´not yet´ ready for Tottenham - Irvine|
|Romero lauds caring Van Gaal|
|Jese flying at Real under Rafa|
|Sampdoria unwilling to pay €10m for Balotelli|
|Mourinho talks up Arsenal title chances|
|Hull sign Ryan Taylor, Sam Clucas|
|Kane, Pochettino hail MLS All-Star test|
|Di Santo sorry for swift Werder departure|
|Mourinho tells Ronaldo: Team honours come first|
|Khedira returns to Juve training|
|Celtic v Qarabag: Champions League return of utmost importance, says Collins|
|Pellegrini: Jovetic had to go|
|Manquillo completes Marseille move|
|Schalke reject Juve´s Draxler bid|
|Blanc: Di Maria deal ´close´|
|Di Santo debut ends in stalemate|
|Fire sign Drogba, trade him to Montreal Impact|
|FIFA and UEFA welcome ruling on third-party ownership|
|Juve kick off title defence against Udinese|
|Stoke sign free agent Afellay|
|Benitez confident Ramos will stay|
|Fenerbahce issue warning to fans|
|UEFA Champions League Preview: De Boer confident Ajax are ready for Vienna test|
|Bility: I am the favourite for FIFA presidency|
|Pienaar to miss start of season|
|Vietnam 1 Manchester City 8: Sterling shines as tourists run riot|
|All-Star Keane relishing Spurs clash|
|Shaun Wright-Phillips joins brother Bradley at Red Bulls|
|Inter 0 Real Madrid 3: Rodriguez stunner caps comfortable win|
|Villa sign Ayew|
|Watford complete Berghuis transfer|
|Robben returns to Bayern training|
|Pulis anxious to make West Brom additions|
|David Luiz eager to welcome ´fantastic´ Di Maria|
|Fernando injury free ahead of new campaign|
|Hummels blames weight issues for poor season|
|Defoe hoping for early Sunderland goals|
|Depay hints at identity of ´surprise´ United striker|
|Tigres UANL v River Plate: Hosts look to bounce back and make history|
|Crespo set for Villa move|
|Terry: I would never join a Premier League rival|
|Van Gaal coy on United future|
|Romero to cover potential De Gea exit - Van Gaal|
|Uruguay win men´s football gold at Pan Am Games|
|Pirlo thanks New York City fans for ´beautiful´ welcome|
|Mexico capitalised on ´the mistakes we made´ - Schafer|
|Herrera delighted with Mexico display|
|MLS Review: Whitecaps build happy home, Pirlo debuts|
|Guardado wins Golden Ball at Gold Cup|
|NZF confirms Olympics disqualification appeal|
|Jamaica 1 Mexico 3: CONCACAF giants complete form turnaround|
|New York Red Bulls 2 Benfica 1: Another scalp for MLS side|
|Romero signs with United|
|Moghreb Tetouan 1 Al Hilal Omdurman 1: Visitors go top|
|Van Gaal rules out Ronaldo bid|
|Pique open to Barca captaincy|
|Pirlo makes MLS bow in thrilling NYC victory|
|Coutinho and Can return for Liverpool U21s|
|Walcott deal ´closer´, says Wenger|
|Arsenal 1 Wolfsburg 0: Walcott the match-winner in Emirates Cup finale|
|Di Santo links up with Schalke squad|
|Lukaku treble sinks Hearts|
|Benitez again refutes Ronaldo rift rumours|
|Pepe sure Ramos will stay at Real|
|City target De Bruyne named Germany´s Player of the Year|
|Montero spoils McCarthy´s Palace debut|
|Lyon 0 Villarreal 2: Soriano, Baptistao seal comfortable win in Emirates Cup|
|Wijnaldum on target as Newcastle are held|
|Mourinho: Rivals trying to buy the title|
|Jovetic set for Inter medical|
|RFS in ´denial´ over racism issue, claims Football Against Racism in Europe|
|Salah not staying at Chelsea - Mourinho|
|Mbemba closes in on Newcastle switch|
|Ibrahimovic: Di Maria will take PSG to another level|
|Delph: Don´t compare me to Pogba|
|Dundee United sign Sneijder|
|Morata relishing new-look Juve strikeforce|
|Strachan "not scared" of England after World Cup qualifying draw|
|Brazil claim football, basketball, handball gold in Toronto|
|Lampard´s debut delayed again, Pirlo ready to play|
|Mourinho open to Premier League matches in US|
|MLS Review: Texas unites to hurt Galaxy|
|Luis Enrique: United can emulate Barca revival|
|Van Gaal singles out Januzaj, hails United´s forwards|
|Blanc still hopeful PSG will sign Di Maria|
|Irish international Cunningham seeks Bristol City exit|
|Italy embracing Spain challenge in World Cup qualifying|
|Dos Santos brothers in doubt for Gold Cup final|
|PSG 1 Chelsea 1 (aet, 5-6 on penalties): Courtois clinches victory for Mourinho´s men|
|United States 1 Panama 1 (aet, 2-3 on penalties): Mejia denies hosts third|
|ES Setif 1 Al Merreikh 1: Sudanese deny title-holders at home|
|CONCACAF admit referee errors in Gold Cup semi-final|
|Dutch favourites in Group A - Deschamps|
|Barcelona 1 Manchester United 3: Rooney, Lingard and Januzaj maintain winning start|