The coast of Panama was first spotted by the Spanish adventurer Rodrigo Bastidas in 1501. One year later Christopher Columbus explored the Caribbean coast in search for a passage that would take him further to the west. During one of these expeditions the conquistadores learned from the natives that a vast ocean not far away south promised a way to rich and distant kingdoms, but in is not until 1513 that Vasco Nunez de Balboa crosses the Isthmus of Panama and discovers what we know today as the Pacific Ocean.
In 1519 Spain decides to build Panama City on the Pacific and a town called Nombre de Dios on the Caribbean side to control what would become the most important colonial trading route. Panama is used then as a starting point for expeditions to South America and soon enough huge quantities of gold, silver and other precious items were being shipped from Lima to Panama City and then carried through the jungle to the Atlantic coast before being sent to Spain.
Of course all this gold readily startled the interest of the pirates, and the history of colonial Panama is marked with a great number of attacks, looting and destructions from the infamous privateers. The most famous of them, Henry Morgan, took the fort of San Lorenzo in 1671 before attacking Panama City. The defeated Spanish governor ordered the city to be burnt so it wouldn't fall intact in the hands of the pirates.