The militants attacked the Villa Rose, a hotel popular with politicians and government officials, in a hail of bullets and explosions at about 8pm on Sunday.
Roughly 21 hours later, national police spokesman Sadik Dudishe told reporters that “the clearance operation in the Villa Rose hotel has ended”.
The militants “killed eight civilians who stayed in the hotel and the security forces succeeded in rescuing about 60 civilians,” he said.
“No one among the civilians was wounded.”
One member of the security forces was killed in the attack and five were injured, he added.
“There were about six attackers involved — five of them were shot and killed by the security forces and one of them detonated himself.”
Authorities gave no details about the identities of the casualties.
The attack underscored the ability of the Al Qaeda-affiliated militants to continue staging deadly attacks in the capital despite coming under pressure from an “all-out war” declared against them by President Hassan Sheikh Mohamud's government.
The heavily guarded Villa Rose is located in a fortified area of the capital a few blocks from the President's office.
The hotel's website describes it as the “most secure lodging arrangement in Mogadishu”, with metal detectors and a high perimeter wall.
Armed checkpoints block roads into the area, which also hosts a prison for high-value terror suspects overseen by the National Intelligence and Security Agency.
Al Shabab, which has been trying to overthrow Somalia's central government for 15 years, claimed responsibility for the attack soon after it began on Sunday.
Somali security forces, supported by local militias, a 20,000-strong African military force and US air strikes, have driven Al Shabab from central parts of the country in recent months, but the offensive has drawn retribution.
On October 29, two cars packed with explosives blew up minutes apart in Mogadishu followed by gunfire, killing at least 121 people and wounding 333.
In August, at least 21 people were killed in a siege of a Mogadishu hotel that lasted 30 hours before security forces were able to overpower the militants inside.
The UN said earlier this month that at least 613 civilians had been killed and 948 wounded in violence this year in Somalia, mostly caused by improvised explosive devices attributed to Al Shabab.
The figures were the highest since 2017 and 30 per cent higher than last year.
Agencies contributed to this report