The fate of the Alakrana was watched closely by the Spanish public
Somali pirates have released a Spanish fishing boat and its crew after holding it for six weeks, Spain's prime minister has confirmed.
Jose Luis Rodriguez Zapatero said the pirates had abandoned the Alakrana tuna boat and that all 36 crew on board were "safe and sound".
The pirates earlier told reporters they were leaving the ship after being promised a ransom of $3.5m (£2.1m).
There was no immediate government confirmation of money having been paid.
The case took on greater urgency after the Spanish navy captured two pirates and took them to Spain to face trial - prompting threats from the remaining pirates to kill the Alakrana's crew.
Addressing a news conference in Madrid, a smiling Mr Zapatero said that he had "very good news" for the entire country.
Zapatero: All crew members are safe
"I can confirm that the Alakrana fishing trawler is sailing freely towards safer waters and that all of its crew members are safe and sound," he said.
The Spanish prime minister did not comment on the reported ransom, saying only that the "government did what it had to do".
By late on Tuesday, the Alakrana had made its way to the open sea accompanied by two Spanish warships, the EU naval force, Navfor, said in a statement.
Argi Galbarriatu, the sister of the vessel's second-in-command, said she had spoken to her brother after the boat's release.
"He told me the word to describe it is that they are relieved, and eager to get to port and come home," she said.
In other developments:
• Pirates seized the MV Theresa VIII, a chemical tanker with a crew of 28 North Koreans in waters off Somalia on Monday, Navfor said
• Navfor guards aboard a Ukrainian cargo ship, the MV Lady Juliet, successfully fought off pirates in the Gulf of Aden, also on Monday
The Alakrana was hijacked last month along with its crew of 36, including 16 Spaniards, eight Indonesians and others from Ghana, the Ivory Coast, Madagascar, Senegal and the Seychelles.
The boat, which is based in the Spanish Basque Country, was seized 400 nautical miles (740km) north-west of the Seychelles island of Mahe, according to coastguards.
Pirate spokesmen who spoke by telephone to news agencies earlier on Tuesday said they were receiving a ransom of between $3.5m and $4m from the Spanish government.
Contacted before the vessel was released, Alakrana skipper Ricardo Blach told Spanish radio that 63 pirates were aboard at one stage, including the leaders of the clan behind the hijacking.
Relative's joy as pirates free boat
Negotiations over the ship were complicated by the capture of two of the alleged pirates by the Spanish navy just days after the Alakrana was hijacked, the BBC's Steve Kingstone reports from Madrid.
When the suspects were brought to Madrid to stand trial, the pirates threatened to start killing hostages unless their compatriots were returned to Somalia.
On Monday, the two Somali men were formally accused in Madrid of armed robbery and kidnapping - but the charges are such that if convicted they could be sent home to serve their sentence.
Scores still held
Somali pirates, using "mother ships" to launch their small-boat attacks on vessels, have extended their range to an area off the Seychelles in recent months in order to evade the navies patrolling the Horn of Africa.
More than 10 ships and 200 hostages are currently being held by pirates operating in waters off Somalia.
Families and friends of the Alakrana's crew held a demonstration this month to demand their return
Many of the pirates began as fishermen and say they are stopping illegal foreign fishing boats stealing Somali fish, BBC international development correspondent Mark Doyle reports.
The upsurge in piracy in the region is a consequence of the failure to find a solution to Somalia's political disputes, our correspondent notes.
The weak central government faces an Islamist insurgency and parts of the country have broken away to form autonomous regions.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.