An American and a Danish aid worker kidnapped in Somalia three months ago have been freed in a rare US military raid.