This Caribbean country is rich with colonial ports and its jungles conceal a history of gold and plunder.

It’s kind of spooky in the jungle, sweaty and dank, with deep growls of thunder adding a theatrical touch of menace to a shadowy old mule path. Howler monkeys are hooting in the treetops and brightly coloured parrots flit through the branches above, restive ahead of the downpour the whole rainforest knows is brewing. Down at bootlace level, a young fer-de-lance slithers over a knot of tree roots and conceals its deadly self beneath a mass of rotting leaves.

Somewhere above the forest canopy the thunderheads shift and for a brief moment a shaft of sunlight filters down through the tangle of vines and creepers, casting an antique silver glow on the path’s mouldy cobbles. Framed by palm fronds and the trunk of a gigantic cuipo tree, the scene could be an engraving in an old, old book. All you’d need is for one of those grand turn-of-the-century illustrators such as Howard Pyle or NC Wyeth to paint in a few of their trademark pirates or some haughty conquistadors in peaked helmets and shiny cuirasses, and you’d have yourself a swell cover illustration for a Boy’s Own tale of snakes, jungles and lost Incan treasure.

And well you might. After all, this is the real deal: a seven-mile stretch of the old Camino de Cruces, the legendary Spanish treasure trail across the Isthmus of Panama, and a setting for one of the Golden Age of Piracy’s most swashbuckling tales: the sack of Panama City by the pirate Henry Morgan in 1671.

Morgan had told them all he was going to do it, but no-one had believed him. It didn’t seem possible for even the toughest pirate captain to lead his band of cutthroats through seventy miles of pestilential jungle and launch a successful attack on one of Spain’s wealthiest New World treasure ports.

But then Panama’s colonial governor had to go and make it personal. After Morgan sacked Portobelo in 1668, the captain sent a note across to His Excellency the governor demanding a ransom of 340,000 pesos for the town and its citizens, or he would burn the place to the ground. The aristocratic Spaniard responded with chilly disdain, saying that he was unaccustomed to corresponding with ‘inferior persons’ and dismissing Morgan as a mere ‘corsair’. In other words, he called the Welshman a pirate.

People didn’t say that to Henry Morgan. Captain Morgan preferred the term ‘privateer’, an important step up the social ladder from a common pirate. Privateers were sea captains who carried Letters of Marque, signed by royal decree, which authorised them to harass His Majesty’s enemies abroad – a kind of 17th-century licence to kill.

His Excellency eventually coughed up the ransom money for Portobelo but Morgan wasn’t a man to forget a slight. In 1671 the touchy privateer made good his threat, assembling an armada of 38 ships off the pirate island of Hispaniola and recruiting more than 2,000 ruthless buccaneers to the cause – English, French, Dutch, virtually every pirate in the Caribbean. Their destination was the rich mainland coast of Spain’s empire in the Americas. Wreaking a trail of havoc along the way, the pirates sacked the fortress at San Lorenzo, on Panama’s Caribbean coast.

From there they turned inland, up the Chagres River and along this cobbled old jungle path to where Panama City lay waiting, in splendid isolation, aloof on the Pacific side. Every year, fabulous Incan treasures would arrive at this port – tonnes of gold and precious stones from Peru, silver from the fabled mines at Potosí – where they were stockpiled before being shipped on to Spain. Here was a prize well worth the taking, or at least it would have been if the governor had not been tipped off that the pirates were on their way.

As it was, most of the good stuff was packed onto galleons, to be hidden away in the Islas de las Perlas, a jewel-like archipelago of 220 tropical islands, 30 miles out in Panama Bay, where Panama City’s wealthiest citizens – those who could afford the panic-rates being charged to get out there – took refuge themselves.

The pirates struck at dawn, on 28 January 1671, emerging from the jungle and swiftly overwhelming the town’s outnumbered defenders. A month-long orgy of fire, torture and pillage followed before finally, like sated locusts, the pirate hordes left, carrying their booty back down the trail to where their fleet waited on the Caribbean shore, leaving Panama City’s dazed citizenry to wander amongst the ruins of what had once been their homes.

Even if the haul wasn’t all the pirates could have hoped for, their audacious attack sent shock waves throughout the Spanish Empire, and also reddened a few faces in London, where a peace treaty had recently been signed with Spain in which England had specifically promised to keep the likes of Morgan on a short leash. And in the best of tabloid tradition, the raid also spawned a reality best-seller.

One of Morgan’s men, a French pirate named Alexandre Exquemelin, penned a lively account of the sacking in his book The Buccaneers of America, with plenty of racy stuff in it about how naked Spanish contessas were slow-roasted over coals to help them remember where they’d hidden their jewellery. The book was a runaway success in multiple languages and many editions, and is still in print today.

Morgan himself, no doubt with an eye to posterity and to his by-then-veryskittish political backers in London, adopted a more elegiac tone in his own version of events: ‘Thus was consumed the famous and ancient city of Panama, the greatest mart for silver and gold in the whole world…’

A lot of rainy seasons have come and gone over the old Camino de Cruces since Morgan passed this way. While the jungle remains as sinister as ever, now it’s part of the Soberanía National Park, a vast wilderness better known for plumage than plunder, with a world record 525 species of bird having been recorded in a single day. And where Morgan and his men camped in a misery of mud and mosquitoes where the trail met the Chagres River, modern hikers are within musket range of a five-star eco resort or an easy half-hour’s drive back to the boutique hotels, cafés and jazz bars in the Casco Viejo, Panama City’s fashionably crumbly colonial quarter – where they still won’t serve Captain Morgan rum.

But nowhere are the changes more apparent than along the Chagres River itself, dammed in 1913 to form Gatun Lake, as part of the Panama Canal project. At 164 square miles, the lake was the world’s largest man-made body of water when it was created. Much of the route Morgan followed is now submerged; to tread the pirate trail through modern Panama, you need to transit the canal.

More than a million ships have passed through the world’s most flamboyant shortcut since it opened in 1914, and waiting to add to that tally on this thundery morning is a sightseeing vessel called the Pacific Queen, its decks bright with tourists in souvenir Panama hats, snapping photos and gazing across the water at the shimmering glass-and-steel skyline of Panama City, which looks more like Singapore or Miami than the steamy adventure port of popular imagination. So many new office towers are sprouting up that local wags have taken to joking it’s the construction crane, not the harpy eagle, that ought to be Panama’s national bird.

It all seems a long way from the bad old buccaneering days – a long way even from the hard-boiled years of the military dictator Manuel Noriega and his drug-thug cronies, and the 1989 US invasion that booted them from power. Once practically a by-word for glamorous danger, Panama City has blossomed into one of Latin America’s most cosmopolitan cities, a glitzy banking capital and a honeypot for real estate tycoons, property developers and well-heeled North American retirees looking for tropical sunshine, an expatriate lifestyle and a safe place to berth their yachts away from the hurricanes that beset the usual run of Caribbean tax havens.

‘Oh, don’t worry, we still get our fair share of buccaneers passing through,’ laughs veteran canal pilot Winston Burgos, as he guides the ship towards the great steel gates of the Miraflores Locks. ‘Only nowadays they wear loafers, fly in on corporate jets and instead of parrots on their shoulders, they have yes-men hovering around, carrying their briefcases.’

It’s a 10-hour passage through the canal, and once out of sight of the city it’s a journey straight from the age of steam, up and over the continental divide through a series of locks and across the great silvery expanse of Gatun Lake, with its islands of virgin rainforest, crocodiles sunning themselves on sandbars, brilliant parrots and white-faced capuchin monkeys swinging through the greenery on shore. Then down through the Gatun Locks on the other side and into the blood-warm waters of the Caribbean at Colón.

The canal’s northern gateway is not a city to linger in, least of all with an expensive Nikon around your neck. It’s best to avoid Colón and head west along the coast, to the picturesque clifftop ruins of San Lorenzo – the Spanish fortress at the mouth of the Chagres River that Morgan sacked on his way to Panama City. From there, head back east to get to the heart of the story, in Portobelo, known variously to history as Puerto Bello, Portovelo and (to the English) Portobello.

If you’ve ever read a pirate book and wondered just what they meant by the ‘Spanish Main’, you need look no further. Geographically speaking, the Spanish Main meant the entire continental coastline around the Caribbean, but from the point of view of pirates and swashbuckling fiction it generally meant one of three principal treasure ports, Veracruz in Mexico, Cartagena in Colombia, and Panama’s very own Portobelo.

It was to Portobelo that the treasure from Panama City was brought during the dry season, by heavily guarded mule train along the Camino de Cruces and down the Chagres River, for shipment on to Seville on the mighty galleons of the treasure fleet which called in here once a year.

These same vessels also brought out rich stores of silks and luxury goods for Spain’s expatriate aristocracy. For several weeks each year, while the fleet was in, Portobelo came alive, with the cream of Panama City’s elite making the trip across the isthmus to party and buy nice things. At the same time, tonnes of plundered Incan silver and gold were loaded aboard the Spanish treasure fleet, beneath the watchful gaze of soldiers manning the town’s three massive fortresses, bristling with cannon, that overlooked the bay.

The thought of all that lovely loot made this place the apple of many a pirate’s eye. Long John Silver speaks wistfully of Portobelo in Treasure Island, but Henry Morgan did something about it. Rather than risk a frontal assault from the sea, he borrowed 23 native canoes, long sleek war vessels called pirogues, and crept up the coast towards the unsuspecting town in the dead of night in 1668.

They made landfall a few miles west of town and came in on the road, much to the surprise of the sentries. Before anyone could raise the alarm, Morgan and his men were rampaging through the streets, having taken the seemingly impregnable port with ease. And so began a fortnight of terror, with the entire town held to ransom and an exchange of letters between the haughty privateer, who arrogantly datelined his letters ‘the English town of Portobello’, and the even haughtier governor in Panama City, 60 miles away, who disdained to correspond with a mere corsair, setting the stage for greater things to come.

The scenic coastal road from Colón follows the line of the pirate’s approach, past the crumbling coral walls of Santiago Fort, Portobelo now just a sleepy backwater mouldering in the tropical heat.

Although Morgan did a first-class job of wrecking the place, he wasn’t the one to put Portobelo out of business; that distinction went to a buccaneering English naval hero named Edward Vernon – also known as Old Grog – who captured the town in 1739 after a hearty bombardment in the now-little-remembered War of Jenkins’ Ear – so called because a Spanish sea captain severed an ear off a British sailor named Jenkins, thereby incurring the wrath of the Royal Navy.

It was a popular war and in celebration of Vernon’s triumph, the name ‘Portobello’ began popping up on maps in every British part of the world, starting with Portobello Road in London.

The Spanish retook the town, and later gave Vernon a thorough drubbing in the waters off Cartagena, but Portobelo’s days as a treasure port were done. Weary of being targets for every pirate in the Caribbean, Spain decided from then on to ship its New World plunder the long way around, via Cape Horn at the southern tip of South America. Portobelo went into a long and terminal decline.

Nothing could be drowsier than Portobelo on a hot, sultry Sunday morning here in the early years of the 21st century, with the murmurings of the litany drifting across the square from the open doors of the town’s old colonial church, and a brace of vultures perched outside, gazing down lugubriously as though listening to the Mass and contemplating past sins.

It seemed a pity to have travelled to one of the gaudiest treasure ports along the old Spanish Main and to not at least have a crack at seeing some gold doubloons, especially since rumours abound of beachcombers here occasionally finding delicious bits of treasure washed up on the sands after a storm. A few discreet questions here and there, a couple of dollars slipped to a shady character selling coconuts beside the bus stop, and then a boy is summoned to take us around to a house tucked away in Portobelo’s ramshackle backstreets, where the raffish accordion strains of vallenato music replace the murmurings of the Nicene Creed.

Here, for a few dollars more, a man who gives his name as Octavio agrees to show us a few of the things he’s found. But these turn out to be not much more than cannonballs mainly, a few badly eroded pieces of eight and an early 19th-century American half-dime. No gold, other than Octavio’s piratical smile, only disingenuous shrugs and vague references to friends of friends who make such finds. The ‘good stuff’, it seems, if it exists outside of myth, isn’t shown to the merely curious.

Then again not even Morgan, with all his powers of persuasion, got to see everything. Back on the Pacific side of the isthmus, in Panama City’s old colonial quarter, I find myself in the incensesweetened nave of St Joseph’s church, whose magnificent altar of gilded mahogany survived the pirate siege by being daubed in mud to look as though it had already been stripped of its gold.

In what must have been as fine a piece of acting as any this side of an Oscar, the priest at the time not only convinced Morgan there was nothing left to steal in his church, but, local lore has it, even sweet-talked the hardened buccaneer into donating a bit of gold for its refurbishment. This same legend has a bemused and sceptical Morgan handing over his donation with the words: ‘I have a feeling you’re more of a pirate that I am.’

Perhaps he was. They were all pirates in those days. After all, Panama itself was built on cutlass and plunder.

Following the sack of Panama City, Morgan retired from being the Terror of the Spanish Main and lived out his days as a gentleman planter in Jamaica. While he was about it, he sat down and had a read of Alexandre Exquemelin’s best-seller, The Buccaneers of America – and sued his old shipmate for defamation: the rascal had called him a pirate.

The article 'In search of pirates in Panama' was published in partnership with Lonely Planet Traveller.