At least two people were killed when ISIL launched an attack on the Iraqi embassy in Kabul on Monday, with a suicide bomber blowing himself up outside the gates followed by three gunmen storming the building.
The assault set off a four-hour firefight that ended only after Afghan security forces said they had killed all of the attackers.
Interior ministry spokesman Najib Danish said two Afghan employees of the embassy had died in the attack. Three police were injured, he said.
As the attack unfolded there were conflicting reports of casualties, with a witness saying he saw the bodies of at least two policemen lying on the road outside the embassy soon after the attack began.
In its claim of responsibility, ISIL said its fighters had killed seven guards but the militant group often exaggerates its claims on the number of casualties inflicted. The attack likely meant to distract attention from the militants' massive losses in Iraq and Syria in recent weeks.
ISIL also claimed only two of its followers were involved in the attack, not four as Kabul officials said, adding to the conflicting reports.
Earlier, Mr Danish said only one policeman was wounded and that there were no fatalities among the security forces or civilians. He said all embassy staffers were safe but that the building had suffered extensive damage with windows broken and several rooms badly burnt.
It was not until the attack ended that both the embassy and the interior ministry realised that two of their Afghan staff had died in the assault.
Afghan president Ashraf Ghani condemned the attack and said it was the government's responsibility to provide protection to international missions.
In Baghdad, Iraqi foreign ministry spokesman Ahmad Jamal condemned the assault as a "terrorist attack".
The attack began with a big explosion that rocked central Kabul shortly before noon, followed by gunfire that lasted for several hours, and two or three more subsequent large explosions.
Police quickly cordoned off the area, barring reporters from coming too close to the scene.
The Afghan interior ministry said a suicide bomber began the attack, blowing himself up at the embassy gate before three attackers stormed inside.
Earlier, Afghan officials had said a car bomb started the assault. Later on, however, it became clear the suicide bomber was on foot and not driving a car.
The ministry said Afghan security forces quickly deployed to the scene, rescuing all the embassy diplomats and employees and taking them to safety.
While the attack was still underway, ISIL's affiliate in Afghanistan claimed responsibility in a statement carried by the extremist group's Amaq news agency.
A police officer in the area, who identified himself only as Abdullah, said the gunfire was initially intense but later became more sporadic. The area was surrounded by armoured vehicles and a large contingent of police and Afghan soldiers.
At least one eyewitness, a store owner who goes by the name of Hafizullah said he saw the bodies of two policemen on the ground before armoured personnel carriers and police arrived to cordon off the area.
More than an hour into the attack, witnesses reported hearing another powerful explosion and said they saw black smoke billowing skyward. It wasn't immediately clear what had caused the later explosion.
"The explosion was so strong. I was so afraid," said Maryam, a woman crying near the site of the attack said. She said she works at the nearby office of Afghanistan's national airline Ariana.
Iraq's embassy is located in a part of the city known as Shahr-e-Now, which lies outside the so-called "green zone" where most foreign embassies and diplomatic missions are located and which is heavily fortified with a phalanx of guards and giant cement blast walls.
By comparison, the Iraqi embassy is located on a small street in a neighbourhood dominated by markets and businesses.
After Iraqi forces, backed by a US-led coalition, recaptured the city of Mosul from ISIL last month, the Iraqi embassy had called reporters to its offices in Kabul to express concerns that the extremist group's local affiliate might stage large-scale attacks elsewhere to draw away attention from the militant group's losses in Iraq.