A suicide bomber blew himself up outside the Iraqi embassy in Kabul today and militants breached the compound, Afghan officials said, in a complex hours-long attack claimed by the Islamic State group.

All the attackers had been killed and the compound secured roughly four hours after the assault began, Afghanistan’s interior ministry said, adding that all embassy staff were safe and only one policeman wounded “slightly”.

Earlier, black smoke billowed into the air above the neighbourhood in north-western Kabul as the sound of gunfire, blasts and ambulance sirens could be heard. Panicked residents, including women and children, could be seen fleeing the area.

The interior ministry said at least four militants had attacked the embassy, beginning with a suicide bomber who detonated his vest at the compound entrance.

“The quick-response police forces arrived in time and evacuated the Iraqi diplomats to safe place. No embassy staff have been harmed, only one policeman was wounded slightly,” a ministry statement said.

The Iraqi foreign ministry in Baghdad said the charge d’affairs was among those evacuated and that it was monitoring the situation with Afghan authorities, without giving further details.

The Islamic State’s propaganda agency Amaq released a statement claiming responsibility for the attack, saying two members “attacked the Iraqi embassy building in the Afghan city of Kabul”.

The embassy is located in northwestern Kabul, in a neighbourhood that is home to several hotels and banks as well as large supermarkets and several police compounds.

“I heard a big blast followed by several explosions and small gunfire,” said Ahmad Ali, a nearby shopkeeper. “People were worried and closed their shops to run for safety. The roads are still blocked by security forces.”

The attack is the latest to rock Kabul, which is regularly devastated by bomb blasts and militant assaults, often killing many civilians.

The resurgent Taliban claim many of the attacks as they step up their bid to drive out foreign forces with a series of assaults across the country.

But the Islamic State group, recently ousted from the Iraqi city of Mosul, have been expanding their footprint in eastern Afghanistan and have claimed responsibility for several devastating attacks in Kabul.

First emerging in 2015, the group’s local affiliate Islamic State Khorasan Province (IS-K), overran large parts of eastern Nangarhar and Kunar provinces, near the Pakistan border, where they engaged in a turf war with the Taliban.

US forces in Afghanistan have repeatedly targeted the group, killing its head Abu Sayed and several senior advisers in a July 11 strike in Kunar, the Pentagon has said.

The decision to deploy the so-called Mother Of All Bombs (MOAB) also targeted IS hideouts in Nangarhar, according to the Afghan defence ministry, though fighting in the area has continued.

Pentagon officials say the group now numbers fewer than 1,000 in Afghanistan.

“We will be relentless in our campaign against ISIS-K. There are no safe havens in Afghanistan,” said General John Nicholson, commander of US forces in Afghanistan, in a statement yesterday confirming some of the deaths in the July 11 strike.

The group is believed to be on the back foot in the Middle East, where analysts have said it has lost more than 60 per cent of its territory and 80 per cent of its revenue, three years after declaring its self-styled “caliphate” across swathes of Iraq and Syria.

But analysts said today’s attack in Kabul would be seen as a warning to Baghdad after it pushed IS out of Mosul.

“(IS) wants to send a message to many states, not just to Iraq, to prove that it is present everywhere... particularly after the victories of the Iraqi security forces in Mosul,” said Issam al-Fili, a professor of Political Sciences at the Al-Mustansiriya University in Baghdad.