Yusuf Mohamed Ismail Bari-Bari, Somalia's permanent representative to the United Nations in Geneva, Switzerland, was among those killed in the attack at the the Makka Al Mukarama hotel in Mogadishu, the Somali government said.
The attack began around 5 p.m. when a car bomb exploded at the hotel's entrance, according to witness Aden Hussein, who said he was meters away from the hotel when the blast happened.
Gunmen then went inside the hotel, shooting people, Hussein said.
One of the attackers, wearing a belt with explosives, blew himself up inside the hotel, police Capt. Ahmed Abdi said
A few hours after the assault began, state-run media reported that security forces stormed the building and killed the remaining assailants.
The attackers killed at least six people, Abdi said.
The hotel, which is along a highway leading to the country's presidential palace, is popular with lawmakers, journalists and business people.
An Al-Shabaab spokesman, Sheikh Abdiaziz Abu Musab, told CNN that the group was behind the attack. He said Al-Shabaab fighters were conducting an operation at the hotel against what he said were spies and government officials.
Al-Shabaab 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.