With the decline of the Spanish Empire and the drying up of the treasures of the Inca Empire, Panama  became a colonial backwater. When independence movements swept through Latin America, Panama eventually got caught up in the tide.
On November 10, 1821, residents of the little town of La Villa de Los Santos  on the Azuero Peninsula  wrote a letter to Simón Bolívar complaining of mistreatment by the Spanish governor and asking for his help. This Primer Grito de la Independencia (First Cry for Independence) is commemorated as a national holiday in Panama.
This was followed 18 days later by a meeting in Panama City  in which Panama broke away from Spain and joined Colombia in an uneasy union that for a while included Venezuela and Ecuador. November 28 is celebrated in Panama today as the first of several steps toward independence.
In 1826, Bolívar called a congress, held in what is now the Casco Viejo  section of Panama City, in an attempt to create a union of Latin American republics. The Congress of Panama took place June 22–July 15. Though Bolívar himself did not attend and the talks ended in failure, the attempt is still considered an important moment in Latin American history.
The isthmus of Panama was in turmoil through much of the 19th century. It attempted three times between 1831 and 1841 to break away from Colombia, but each time it failed.
One of the bloodiest incidents of the 19th century in Panama was the so-called Prestán Uprising of 1885. Depending on whom one chooses to believe, Pedro Prestán was either a revolutionary martyred in the cause of freedom or a rabble-rousing mulatto with an irrational hatred of foreigners, especially white ones.
When a former president of the department of Panama, Rafael Aizpuru, tried to seize power in Panama City , Colombian troops were dispatched to the city from the Caribbean side of the isthmus, leaving the city of Colón  largely undefended. Prestán took advantage of this, reportedly leading a band of machete-wielding men in a looting spree along Front Street.
He then took hostages, whom he threatened to kill if the U.S. warship Galena, at port in Colón, landed troops. He also demanded he be given a shipment of arms that had been smuggled by ship and were waiting for him in the harbor.
The commander of the Galena had been ordered not to interfere in Panama’s domestic affairs unless the Panama Railroad was threatened, which so far it hadn’t. The American consul, one of Prestán’s hostages, promised to turn over the weapons. Prestán released the hostages, but the Galena towed the steamer with the cargo of guns away from shore before Prestán could get access to them.
On March 31, Colombian troops returned from Panama City and battled Prestán’s men at Monkey Hill, just outside the city. Routed, Prestán allegedly set fire to Colón as his men retreated. The city, which was built almost entirely of wood, burned to the ground, leaving at least 18 dead and thousands homeless. The Colombian troops rounded up dozens of Prestán’s men and executed them. Prestán himself was tried and hanged in Colón, above the railroad tracks. Aizpuru, whose own failed rebellion in Panama City left dozens dead, was sentenced to 10 years in exile.
The isthmus was also the scene of major battles in the War of a Thousand Days (1899–1902), a Colombian civil war fought between the Liberal and Conservative parties.
One of the most important of these was the battle of La Vieja Negra, fought outside the city of David  in western Panama on March 31, 1900. Liberals who had taken refuge in Nicaragua from the ruling Conservative party invaded Panama from the west, captured David, and defeated better-trained and -equipped Conservative forces at La Vieja Negra, after which they marched on Panama City  and were defeated.
A peace treaty was signed on July 26, 1900, but was quickly broken. Bloody battles continued to flare up around the isthmus. Colombia called on the United States to intervene, and the war finally came to an end with the signing of a peace treaty aboard the warship U.S.S. Wisconsin on November 19, 1902.
Though the Liberals lost the war, Panama considers the leaders of the Liberal forces to be heroes and founding fathers of the country. These include Belisario Porras, the civilian head of the isthmian forces, and Victoriano Lorenzo, who commanded an army of his fellow cholos (people of indigenous descent but Latino culture) that played a key role in many of the battles.
Porras would later serve as president three times when Panama finally became an independent country. Although the peace treaty was supposed to grant the combatants amnesty, Lorenzo was executed by firing squad on May 15, 1903, which Panama remembers as one of the darker days in its history.