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 northwestern 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 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.
More From This Section
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".
"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.
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.
"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.
"(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.