Among the dead was a Somali-American woman, Fahia Bashir Nur, 45, of Alexandria, Virginia, according to her uncle, Yusuf Kheire. He said Nur and her mother were dining in the hotel when the attack began. The mother lost an arm in the attack and was hospitalized.
The attack, which lasted hours, began when gunmen raided the hotel in Mogadishu on Friday evening.
Yusuf Mohamed Ismail Bari-Bari, Somalia's permanent representative to the United Nations in Geneva, Switzerland, was among those killed in the attack, the Somali government said.
"He will be remembered for his strong personal commitment to protecting and promoting human rights for all," Nicholas Kay, special representative of the United Nations Secretary-General to Somalia, said of Bari-Bari.
Islamist militant group Al-Shabaab claimed responsibility.
The attack started about 5 p.m. local time when a car bomb exploded at the hotel's entrance, according to witness Aden Hussein, who said he was nearby when the blast happened.
Gunmen then stormed into the hotel and opened fire, Hussein said.
They overpowered the hotel's security guards, said police Capt. Ahmed Abdi, adding that the gunbattle between Somali special forces and the attackers lasted at least 17 hours.
One of the attackers, who was wearing a belt with explosives, blew himself up inside the hotel, police Capt. Ahmed Abdi said.
Some members of the terror group "stormed into the first, second and third floors of the hotel where rooms are located and held several people hostage," according to a statement from the African Union Commission in Somalia, a peacekeeping mission.
The Makka Al Mukarama hotel, located along a highway leading to the country's presidential palace, is popular with lawmakers, journalists, business people and Somalis returning home from abroad.
Somali President Hassan Sheikh Mohamud condemned the attack as a "heinous and inhuman act" in an interview with state-run Radio Mogadishu during an official visit to Egypt.
In a statement, Somali Prime Minister Omar Abdirashid Ali Sharmarke said Al-Shabaab's "talk of 'legitimate targets' and 'justification'" exposes "the sham logic behind their lust for terror."
"These terrorists contradict Islam and betray Somalia," he said.
The injured, along with the bodies of the dead, could not be removed from the hotel until after the hours-long gunfight.
More than 10 people, most of them Kenyan nationals who worked at the hotel, were rescued, police said.
Al-Shabaab said it targeted the hotel because its guests are spies and government officials.
The terror group has been active in Somalia for years.
Initially, its goal was implementing a stricter form of Islamic law, or Sharia, by warring against the Somali government. It has since shifted its focus to launching terror attacks in Somalia and beyond.
"We reiterate again that there will be no safe haven for the crusaders and apostates in Somalia, and that our attacks on them will continue until the enemy of Allah (is) defeated and his law is implemented fully in Somalia," the group said in a statement.