The crew of the Spanish-owned Playa de Bakio must have felt they were safe. Fishing for tuna more than 200 nautical miles off Somalia's coast last weekend, they were surely out of the pirates' range. But they had not reckoned with the 'mother ship' lurking nearby.

A hijacked trawler was now the pirates' base; it was towing their high-powered speedboat. The Playa, with 26 crew, was easy pickings for an experienced militia armed with AK-47s and rocket-propelled grenades.

For the second time in a fortnight Somali pirates had captured a European-registered and crewed ship, the most lucrative prize. The French luxury yacht Le Ponant, hijacked on 5 April with 30 crew on board, netted a $2m (£1m) ransom, despite the close attention of France's military. Last night the Playa and its crew were safely heading for home waters, escorted by a Spanish frigate after negotiations between the pirates and the Spanish government, which refused to say whether an equally lucrative ransom had been paid.

Vice-President María Teresa Fernández de la Vega said the release had been achieved through 'co-operation and diplomacy' between Spain, the ship's owners and representatives of the hijackers.

The hijackings are confirmation, if any were needed, that the waters off Somalia are the most dangerous in the world. Last year, there were 31 attacks there, making the notorious bandits operating in the South China Sea and Malacca Straits look almost lazy by comparison. So far this year there have been 23 attacks by Somali pirates, including the 47-day hijacking of a new, British-captained icebreaker tug, the Svitzer Korsakov, on its way from Europe through the Gulf of Aden towards the gas fields in far eastern Russia. The ransom paid for its release was reported to be $1.6m.

It is not only the frequency of the attacks off Somalia that has maritime experts deeply worried. It is the skill and daring of the pirates, some of whom call themselves 'marines' and claim to be protecting the country's maritime resources from foreign exploitation.

Until five years ago, captains were advised to stay at least 50 miles away from Somalia's coastline. A spate of hijackings led to a doubling of the safety zone. Now, the recommended safe distance is 200 miles, but the Playa attack shows even that is no guarantee of safety. With the large ransoms allowing the pirates to buy faster boats, and more sophisticated GPS systems, they can strike even in rough waters several hundred miles out to sea.

The surge in attacks coincides with the worst unrest in Somalia since the early Nineties - the last time the country had a functioning government. Insurgents are battling Ethiopian troops who toppled an Islamist authority from power in December 2006. More than half the population of Mogadishu has since fled the city.

The Transitional Federal Government (TFG) of President Abdullahi Yusuf, which is packed with former warlords, exercises little authority and claims to be unable to stop the piracy. But it is perhaps telling that during the six-month reign of the Somali Council of Islamic Courts over much of south and central Somalia in 2006, attacks on passing ships all but stopped.

Andrew Mwangura, head of the Mombasa-based Seafarers' Assistance Programme, and one of the foremost experts on Somali piracy, says there are five main pirate groups operating, sometimes together.

'Most of them are linked to warlords,' he said. 'And the warlords are linked to the TFG, all the way to the top.'

Monitoring Somalia's 1,880-mile coastline, the longest in Africa, is no simple task. For several years a joint US-European naval unit has patrolled the region, which is on the trade route between the Mediterranean, east Africa and Asia, in an attempt to discourage attacks and keep an eye out for terrorists. But the bandits simply shifted their bases north to the semi-autonomous Puntland region.

One-off military operations, such as the raid in Somalia's desert by French special forces to arrest six of the pirates who had attacked Le Ponant, are ineffective deterrents, say experts. Piracy is simply too profitable.

A gunman on a pirate ship typically earns between $10,000 and $30,000 for a year's work - a fortune in Somalia. Those bankrolling the attacks from bases in the United Arab Emirates or Kenya, and sometimes as far afield as Canada, London or Hong Kong, can net several million dollars from a single strike, depending on the nationality of the shipowner, the origins and gender of the crew, the cargo and the age of the boat.

'Once the pirates' bosses have the ship's name they immediately use the internet to research how much money they can make,' said Mwangura. 'These guys really know what they are doing.'

Most owners pay up quickly, transferring money through a network of accounts in Nairobi, Mombasa and Dubai. The crews are seldom harmed. When older, less valuable trawlers - often from Taiwan or China - are captured, the demand is not cash but the temporary use of the boat. The owners promise not to report their vessel missing, and it becomes a temporary 'mother ship'.

In the past, pirates have attacked a cruise liner, as well as several cargo ships chartered by the UN World Food Programme containing food aid meant for Somalis. But as bizarre as it sounds, there is some truth in the pirates' claim that they are acting as a coastguard. Under international law, a country's 'exclusive economic zone' - where it has sole rights over marine and mineral resources - extends 200 nautical miles out to sea. Foreign ships are allowed to pass through these waters, but not to fish without a permit.

Yet at any one time there are up to 500 foreign-registered boats fishing in Somalia's rich waters, according to the Seafarers' Assistance Programme. European boats catch tuna or shrimp; vessels from the Far East catch sharks for their fins. Almost all are fishing illegally. Often, pirate attacks are not even reported to maritime authorities: the ransoms paid are regarded as legitimate fines, both by the pirates and the ship-owners.

'One way to stop the piracy is to stop the illegal fishing,' said Mwangura. 'That way there will be nowhere for the pirates to hide.'