Mexico's 2014 World Cup hopes survived a 2-1 loss at Costa Rica on Tuesday, but only thanks to arch-rivals the United States, whose two injury-time goals spelled heartbreak for Panama.
On a wild final night of qualifying in North and Central America and the Caribbean, Honduras punched their ticket to Brazil on cue with a 2-2 draw at last-placed Jamaica.
They claimed the third and final automatic qualifying berth from the region behind the United States and Costa Rica.
Mexico, the longtime regional powerhouse who have played in every World Cup since 1990, have endured a dismal qualifying campaign.
But they finished fourth in the table to earn a playoff next month against Oceania's New Zealand for a berth -- thanks to the late heroics that saw the United States down Panama 3-2 and end Panama's hopes of seizing the playoff spot.
On a rain-sodden pitch in San Jose, second-half substitute Alvaro Saborio scored the winner for Costa Rica, heading past Mexico goalkeeper Guillermo Ochoa in the 64th minute.
Mexico seemed done for shortly thereafter when in Panama City, Luis Tejada struck to give Panama a 2-1 lead over the United States.
But Graham Zusi scored for the USA two minutes into injury time and Aaron Johannsson added another goal to seal a 3-2 US triumph.
Mexico had missed a chance to take an early lead when Javier "Chicharito" Hernandez fired weakly into an open Costa Rican goal. The play was set up by Oribe Peralta, who was then called offside when he moved to tap in Hernandez's miss.
Moments later, Brian Ruiz gave Costa Rica a 1-0 lead in the 26th minute, collecting a high ball and gaining room with a header that he turned and fired past Ochoa with his left foot.
At that point, Panama had taken a 1-0 lead over the United States and held the edge on Mexico in the race for the playoff.
But Peralta grabbed the equalizer in the 29th minute to put Mexico back in it. Costa Rican Keeper Keylor Navas surged out of his net to stop a shot from Hernandez. The ball went to Peralta, who fired it into the open net.
Hernandez departed in the 60th minute, replaced by the hero of Friday's 2-1 win over Panama, Raul Alonso Jimenez.
But it was Costa Rica who found the go-ahead goal in the rain-swept second half as Saborio, who came in for Ruiz in the 49th minute, headed home the deciding goal.
Mexico seemed doomed when Tejada's 84th-minute strike gave Panama a 2-1 lead over the United States.
But Panama's hopes of staying in the hunt for a first ever World Cup berth were cruelly dashed by Zusi's header, which was followed a minute later by Johannsson's game-winner from the edge of the penalty area.
The drama playing out in San Jose and Panama City reduced Honduras' clinching draw in Kingston to a footnote.
Carlo Costly showed just how determined the Hondurans were to claim a second straight -- and third overall -- World Cup trip, when he opened the scoring in the first minute.
Jamaica struck back just two minutes later through Je-Vaughn Watson, but Honduras held a 2-1 lead at halftime thanks to Maynor Figueroa's 33rd minute strike.
Even Rodolph Austin's 58th-minute penalty for Jamaica couldn't spoil it for Honduras, who came into the match needing just one point to secure third place.
The US finished the "hexagonal" final round on 22 points, with Costa Rica second on 18 and Honduras third on 15.
Mexico wrapped up fourth place with 11 points, three more than Panama, and Mexico manager Victor Vucetich said he was sure his side could triumph over New Zealand in the home-and-away playoff next month.
"I definitely think we can beat New Zealand," he said. "I am completely confident in that sense. We know we have capable people who maybe are having a difficult time, but we have confidence in everyone and we feel that we will advance."