Denmark has been operating against Somali pirates since 2008
Danish special forces serving as part of Nato's counter-piracy operation have freed the crew of a cargo ship boarded by pirates off Somalia.
They moved in after being assured by the captain that the crew had locked themselves in a safe room, a Nato spokeswoman told the BBC.
It seems the pirates escaped to their boat before the troops arrived but the 180m (590ft) vessel was being searched.
A second pirate boat in the area was seized by a Russian warship, Nato says.
Admiral Sir Trevor Soar, commander of the Nato Maritime HQ in London, commended the actions of the Danish warship Absalon, which carried out the rescue.
"Absalon's action today demonstrates Nato's resolve to deter and disrupt piracy off the Horn of Africa," he said in a statement.
He also thanked the Russian and Indian navies for assisting in the operation.
A distress signal was received from the master of the Antigua and Barbuda-flagged Ariella on Friday morning, reporting that six heavily armed pirates had boarded the ship, Nato spokeswoman Lt Cdr Jacqui Sherriff told the BBC.
The attackers' skiff and a second boat were seen in the area of the attack about 160km (100m) off the Somalia coast.
Informed that the crew had managed to lock themselves away, the Absalon first sent out a helicopter to investigate, then a team of specially trained forces in inflatable dinghies to board the ship and regain control.
The crew, said to be 25 strong, were released safely.
Cmdr Dan B Termansen, commander of the Absalon, said that the crew had reported seeing a pirate firing an automatic weapon aboard their ship.
"I don't know if he jumped overboard when he saw the helicopter or later when he saw the special forces," he added.
"We searched the ship for hours and didn't find anybody."
However, Cmdr Mikael Bill, head of the Danish Admiralty in western Denmark, said he did not believe there had been any pirates aboard the ship when the special forces arrived.
"It is our clear understanding that there were no hijackers on board but our helicopter had deterred an action," he said.
A Russian warship, the Neustrashimy, successfully boarded and detained the pirates in the second skiff.
Cdr John Harbour, a spokesman for the EU Naval Force in Nairobi, praised the Nato operation.
It was, he told the Associated Press news agency, the first instance where a warship had been able to "send forces to stop a hijacking while it was in progress".
Warships typically do not intervene in hijackings because of the danger that crews may be hit by crossfire, he pointed out.
However, in this case the ship had registered with naval authorities, was travelling along a recommended transit corridor and was part of a group transit, ensuring the ships had a helicopter within 30 minutes' reaction time.
The waters off Somalia are among the most dangerous in the world, despite patrols from EU and other foreign naval forces.
Somalia, riven by war, has had no functioning government since 1991, allowing pirates to operate along the lawless coast, almost with impunity.