There were conflicting reports of casualties as the attack unfolded, with a witness saying he saw bodies of at least two policemen lying on the road outside the embassy soon after the attack began.
In its claim of responsibility, Islamic State said its fighters had killed seven guards but the militant group often exaggerates its claims on the number of casualties inflicted. The attack was likely meant to distract attention from the militants' massive losses in Iraq and Syria in recent weeks.
Also, Islamic State said only two of its followers were involved in the attack, not four as Kabul officials said, adding to the conflicting information.
Interior Ministry spokesman Najib Danish said only one policeman was wounded and that there were no fatalities among the security forces or civilians. Danish told the Associated Press over the phone that all the embassy staffers were safe but that the building had suffered extensive damage with windows broken and several rooms badly burned.
In Baghdad, Foreign Ministry spokesman Ahmad Jamal condemned the assault as a "terrorist attack."
The attack began with an 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 Interior Ministry said a suicide bomber first started the attack, blowing himself up at the embassy gate, after which three attackers stormed inside.
Earlier, Afghan officials who spoke on condition of anonymity as they were not authorized to talk to the media, had said a car bomb started the assault. Later, it became clear the suicide bomber was on foot and not driving a car.
The ministry statement 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, the Islamic State affiliate in Afghanistan claimed responsibility in a statement carried by the Islamic State-linked Aamaq 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 armored vehicles and a large contingent of police and Afghan soldiers.
At least one eyewitness, a store owner who goes by the name of Hafizullah — many Afghans use only one name — said he saw the bodies of two policemen on the ground before armored 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.
The Iraqi Embassy is located in a part of the city known as Shahr-e-Now, which lies outside the "green zone" where most foreign embassies and diplomatic missions are located and which is heavily fortified with a phalanx of guards and large concrete blast walls.
By comparison, the Iraqi Embassy is located on a small street in a neighborhood dominated by markets and businesses.
After Iraqi forces, backed by a U.S.-led coalition, recaptured the city of Mosul from Islamic State earlier in July, the Iraq Embassy had called reporters to its offices in Kabul to express concerns that the local Islamic State affiliate might stage large-scale attacks elsewhere to draw away attention from the militant group's losses in Iraq.
6:05 a.m.: This article was updated throughout with additional details and background.
3 a.m.: This article was updated to clarify that a suicide bomber, not a car bomb, started the attack.
1:35 a.m.: This article was updated with the Afghan Interior Ministry saying the Iraqi Embassy diplomats were safe.