U.S. helicopters swooped into Somalia on Wednesday and rescued an American and a Dane after a shootout with pirates holding them hostage, in a rare raid into the Horn of Africa nation to free foreign captives.

The aid workers, American Jessica Buchanan and Dane Poul Hagen Thisted, were kidnapped from the town of Galkayo in the semi-autonomous Galmudug region in October while working for the Danish De-mining Group (DDG).

This case is special ... we are dealing with one of the hostages having an illness which is very serious, and this is the reason there was made a decision to go in and take action, Danish Foreign Minister Villy Sovndal told Denmark's TV 2 News.

We cannot conclude ... that it is something that will be done in future cases.

The Danish Refugee Council said Buchanan and Thisted were unharmed and at a safe location. Media reports said they had been flown to neighbouring Djibouti, home to the only U.S. military base in Africa and France's largest base on the continent.

People involved with the hostages had said earlier this month Buchanan was suffering from a possible kidney infection.

Somali pirate gangs typically seize ships in the Indian Ocean and Gulf of Aden and hold the crews until they receive a ransom. The kidnapping of the aid workers in Galkayo was an unusual case of a pirate gang being behind a seizure on land.

While U.S. and French forces have intervened to rescue pirate hostages at sea, attacks on pirate bases are very rare.

Galmudug leader Mohamed Ahmed Alim told Reuters nine pirates were killed and five captured during the rescue operation near the pirate haven of Haradheere.

Alim was speaking from Hobyo, another pirate base north of Haradheere, where he said he was negotiating the release of an American journalist seized on Saturday, also from Galkayo.

About 12 U.S. helicopters are now at Galkayo. We thank the United States. Pirates have spoilt the whole region's peace and ethics. They are mafia, Alim said.

MORE HOSTAGES

Pirates and local elders say the American journalist and a number of sailors from India, South Korea, the Philippines and Denmark are being held by pirate gangs.

A British tourist kidnapped from Kenya on September 11, 2011 is also still held captive in Somalia.

America's NBC News, citing U.S. officials, said two teams of U.S. Navy SEALs (special forces) landed by helicopter and rescued the hostages after a gun battle with the kidnappers.

The freed hostages were then taken by helicopter to an undisclosed location.

U.S. President Barack Obama was overheard congratulating Defence Secretary Leon Panetta, apparently for the success of the operation, as Obama entered the House of Representatives chamber on Tuesday for his annual State of the Union speech.

Leon. Good job tonight. Good job tonight, Obama said.

Panetta visited U.S. troops in Djibouti last month on his way to Afghanistan and Iraq, in a stopover that reflected Obama's growing focus on the militant and piracy threats from Yemen and the eastern edge of Africa.

In Djibouti, the United States has a platform to monitor, partly by using surveillance drones, al Qaeda in the Arabian Peninsula (AQAP) in Yemen and Somalia's al Shabaab, a hardline rebel group with links to al Qaeda.

Somalia's government applauded the mission and said it welcomed any operation against pirates.

U.S. special forces killed senior al Qaeda militant Saleh Ali Saleh Nabhan in a raid in southern Somalia in 2009. Several other al Qaeda or al Shabaab officials have been killed in U.S. drone strikes in Somalia over the past few years.

It was also U.S. Navy SEALs who killed al Qaeda leader Osama bin Laden in a raid on his Pakistan home in May.

(Additional reporting by Mohamed Ahmed in Mogadishu, John Acher and Mette Fraende in Copenhagen, David Clarke in Nairobi and Eric Beech in Washington; Writing by Richard Lough and David Clarke; Edited by Richard Meares)