Attackers who stormed a hotel in Mogadishu killing 23 people and wounding more than 30 on Saturday used identity cards from the country’s intelligence service to gain access to the building.

The five gunmen, from the Islamist al-Shabaab militant group, were dressed in intelligence service uniforms and did not draw suspicion as they entered the hotel in the centre of the Somali capital after a truck bomb demolished a well-defended front entrance.

The gunmen then held off security forces for more than 12 hours, and went room to room shooting guests. A senior regional minister and a mother with her three young children whom the attackers believed were his family were among the dead.

“They had ID cards which had clear information such as names, ranks and photos so no police officer could stop them,” said a senior intelligence officer, Col Ahmed Yare

Al-Shabaab claimed responsibility on one of its websites 55 minutes after the initial bombing of the hotel. Sheikh Ali Mohamed, a religious cleric who survived the attack on the hotel saw the attackers kill the woman and children.

“They are ruthless. They are not Muslims. They have no mercy for human life,” he said.

The attacks come only two weeks after a massive bomb killed more than 350 people in Mogadishu, which has also been blamed on al-Shabaab, and raises serious questions for the Somali security establishment.

The use of National Intelligence and Security Agency (NISA) uniforms and cards will also raise concerns over possible sympathies for the insurgents among low-level members of the force.

Somalia’s government fired two of the country’s most senior security officials after the attack. A statement from the prime minister’s office on Sunday said Abdullahi Mohamed Ali, the NISA director general, and Gen Abdihakim Said, the head of police, were sacked following a cabinet vote.

The move is aimed at restoring public confidence. The truck bombing two weeks ago on a busy Mogadishu street is one of the single most lethal terrorist strikes in recent years anywhere in the world.

Somali investigators said al-Shabaab was behind that bombing, though the group did not claim responsibility.

The Naso-Hablod hotel, which was attacked on Saturday, is known as a favoured haunt of government officials. Somali special forces managed to secure the building on Sunday morning. Three gunmen were killed and two captured, officials said.

Analysts said the al-Shabaab prompt claim of responsibility for Saturday’s attack was in part intended to contrast with its failure to claim responsibility for the devastating attack this month.

Al-Shabaab says it strikes only military or official targets and would have seen no advantage in taking responsibility for an operation that killed many civilians and failed to hit its target, thought to be the heavily fortified airport compound in Mogadishu, which is home to the UN, embassies and the headquarters of African Union troops in Somalia.

The group, which has been fighting to establish an Islamist state in Somalia for a decade, has been hit hard in recent years by a series of offensives by government troops and the 22,000 African Union forces stationed in the country.

Significant casualties have also been inflicted on al-Shabaab’s leadership by US drones. The US has been ramping up its presence in the anarchic and drought-hit east African country for some time, with a new push since Donald Trump took power.

Trump has authorised the deployment of regular US forces to Somalia for the first time since 1994. The US in effect pulled out of Somalia after 1993 when two helicopters were shot down in Mogadishu and the bodies of American soldiers were dragged through the streets.

Somalia’s president said the latest attack on the capital aimed to instill fear among people who showed unity after the bombing two weeks ago. “They want to create fear among our people who showed support to the ongoing efforts aimed at pacifying the country,” President Mohamed Abdullahi Mohamed, who took power in February, said in a statement.

Ali, the sacked intelligence chief, recently wrote a lengthy article in the New York Times criticising the international community for failing to help Somali security forces. “We appealed to our international partners to share all information and evidence that they gathered from bombings in Somalia with the national authorities. The silence was deafening,” Ali wrote.

Suggestions that Ali was fired as a result of the article were misplaced, said one international official who works closely with the Somali government. “There is simply a lot of public anger around at the moment and someone needed to carry the can,” the official said.

Most Somali civil servants, troops and police have not been paid for several months, undermining morale.