US Navy Seals (Sea, Air and Land Teams) flew into central Somalia's Galmudug region by helicopter to launch the pre-dawn raid on the kidnappers' base, according to local officials.
American Jessica Buchanan and Dane Poul Thisted, who worked for the Danish Refugee Council Demining Group, were unharmed and flown to safety, their employer said.
President Barack Obama
Jessica Buchanan was selflessly serving her fellow human beings when she was taken hostage by criminals and pirates who showed no regard for her health and well-being.
Mohamed Ahmed Alim, the president of the semi-autonomous region, told Reuters news agency that nine suspected pirates were killed and five injured during the rescue operation.
"About 12 US helicopters are now at Galkayo. We thank the US. Pirates have spoilt the whole region's peace and ethics. They are mafia," he said.
US President Barack Obama was apparently overheard congratulating defence secretary Leon Panetta on the successful rescue as he entered the House of Representatives to give his State of the Union speech.
"Leon. Good job tonight. Good job tonight," Mr Obama said. He did not mention the rescue during his speech.
In a later statement, Mr Obama said: "As commander-in-chief, I could not be prouder of the troops who carried out this mission, and the dedicated professionals who supported their efforts.
"Jessica Buchanan was selflessly serving her fellow human beings when she was taken hostage by criminals and pirates who showed no regard for her health and well-being."US aircraft are believed to have flown into Galkayo before launching the raid
A number of nations, including the US, with naval vessels in the Indian Ocean and Gulf of Aden off Somalia have intervened to rescue hostages held by the pirates at sea, but it unusual for a rescue operation to be launched inside the country.
However, the US and France both have military bases in nearby Djibouti.
The Danish Refugee Council had been trying to secure the freedom of Ms Buchanan and Mr Thisted, who were seized by gunmen on October 25, through local elders.
However, the timing of the raid may have been made more urgent by a medical condition.
"One of the hostages has a disease that was very serious and that had to be solved," Danish foreign minister Villy Soevndal told Denmark's TV2 channel.
Somalia is one of the world's most dangerous regions for aid workers and some pirate gangs have branched out to kidnappings.
Pirates are also believed to be behind the abduction of an American-German writer Michael Scott Moore, who was seized on Saturday in Galmudug, the region where the pirate ports of Hobyo and Haradheere are located.