Hernan Dario Gomez's men looked set to miss out on even an intercontinental play-off spot as it was level 1-1 with Costa Rica in Panama City, the host having equalised as Gabriel Torres' close-range effort cancelled out Johan Venegas' opener for Costa Rica.
That effort proved controversial as the ball looked to have failed to cross the line, but it appeared it would be inconsequential with the draw not enough to overhaul United States and Honduras beating Mexico 3-2.
But, three minutes from time, Roman Torres sent Estadio Rommel Fernandez into delirium, the defender bursting on to a header forward and lashing the ball home to make history for Panama at the expense of USA, which lost 2-1 to Trinidad and Tobago.
Panama progressed to the finals, while Honduras' victory sends them into a play-off with Australia, and president Juan Carlos Varela has elected to let the country celebrate the historic moment for a further 24 hours.
Juan Carlos Varela posted on Twitter: "The voice of the people has been heard; celebrate this historic day for Panama. Tomorrow [Wednesday] is a national holiday.
"It is a historic day for the country. Tomorrow will be free for the public and private sector workers.
"On a national holiday, also classes are suspended at the country's private and public schools, celebrate family."
La voz del Pueblo ha sido escuchada; celebra este día histórico para Panamá. Mañana será Día de Fiesta Nacional. pic.twitter.com/RJWNyTs06L— Juan Carlos Varela (@JC_Varela) October 11, 2017