Romell Quioto scored the winner in the 60th minute for Honduras, who will now face Australia in a two-leg playoff in November for another ticket to Russia.
Panama's win was not without controversy.
After the visitors went ahead through Johan Venegas' neat chip in the first half, a 53rd minute Panama corner bounced awkwardly off Gabriel Torres towards the net and while forward Blas Perez dived head first to try to force it home the ball was blocked on the line by Ronald Matarrita.
Somehow the Costa Rican defender scrambled it clear but the referee, who had been standing outside the box, awarded the goal.
There was no doubt about the winner from Roman Torres, however, after he hammered home a volley in the 88th-minute to spark wild celebrations in the stadium.
That goal not only sent Panama to their first World Cup but ensured the United States would miss out.
The Americans, who were sitting pretty in the final qualifying spot heading into Tuesday's game, fell behind to an own goal in the 16th minute from defender Omar Gonzalez and went two down when Alvin Jones scored eight minutes before half-time.
Christian Pulisic pulled one back shortly after the break but the United States failed to grab an equaliser.
"It was one of the most unlucky goals ever for myself and is one that will haunt me forever," a guilt-stricken Gonzalez told reporters.
Mexico, who had already qualified for Russia as group winners, took the lead in Honduras when forward Oribe Peralta blasted home from close range in the 17th minute.
The home side equalised 17 minutes later through Alberth Elis before Mexico's Carlos Vela responded with a strike five minutes later to put his team up 2-1.
Honduras equalised in unusual fashion when a bullet of a shot hit the crossbar and ricocheted off the back of the head of Mexican goalkeeper Guillermo Ochoa for an unlikely own goal.
Quioto then scored the crucial third for Honduras on the hour to hand Mexico their first defeat of the round and book their place in the playoffs against the Socceroos.
(Reporting by Rory Carroll; Editing by Peter Rutherford)