The Islamic State (IS) extremist group claimed responsibility for a July 31 attack on the Iraqi Embassy in Kabul that killed two local employees.
Afghan officials said the assault began with a suicide bomber blowing himself up outside the embassy gate, allowing three gunmen to enter the building and setting off a four-hour shootout with security forces.
The Afghan Interior Ministry said in statement that "all the attackers have been killed" by security forces.
Two Afghan employees of the embassy were killed and three people were wounded in the attack, the ministry said.
Afghan President Ashraf Ghani condemned the assault and said it was his government's responsibility to provide protection to international missions.
Iraqi Foreign Ministry spokesman Ahmad Jamal condemned the assault as a "terrorist attack."
As Afghan security forces were still battling the attackers, Iraq’s Foreign Ministry said its top diplomat in Kabul was evacuated to the Egyptian Embassy and that attempts were under way to remove two Iraqi staffers.
In its claim of responsibility for the attack, IS said that only two of its followers were involved in the assault, not four as Afghan officials said.
The attack came two weeks after the Iraqi Embassy held a rare news conference to celebrate the government's recapture of the city of Mosul from IS fighters.
During the gathering in Kabul, the Iraqi ambassador, Farazdak Al-Ghalli, expressed concerns that the local IS affiliate might stage attacks elsewhere to draw attention away from the extremist group's losses in Iraq.
The Iraqi Embassy is located in Kabul's Shar-e-Naw area, outside the heavily-fortified "green zone," where most foreign diplomatic missions are located.
The local IS affiliate first emerged in Afghanistan's eastern Nangarhar and Kunar provinces in 2015.
U.S. and Afghan forces have repeatedly targeted the militant group, killing its top local commander, Abu Sayed, and several senior advisers in a July 11 strike in Kunar, the Pentagon has said.
In April, U.S. forces used the army's largest nonnuclear bomb -- nicknamed the Mother of All Bombs -- on IS hideouts in Nangarhar, the Pentagon said. U.S. and Afghan officials said that 96 IS militants were killed in the April 13 attack.
According to Pentagon officials, the group now numbers fewer than 1,000 in Afghanistan.
With reporting by AP, Reuters, AFP, and dpa