Gunmen stormed the Iraqi Embassy compound in Kabul after a suicide bomber blasted open the gates to the site Monday, forcing diplomats and others to flee as Afghan security forces battled the attackers, officials said.

Interior Ministry spokesman Najib Danesh told reporters that two Afghan employees of the embassy were killed and three policemen were injured, the Associated Press reported. The three gunmen who entered the compound were killed during the shootout, which lasted nearly four hours.

The Islamic State-affiliated news agency Amaq claimed that militants from the group carried out the assault and killed at least seven guards. The claims could not be immediately verified.

Danesh said all embassy staff were moved to a safe location.

The attack began with an explosion outside the embassy, authorities said. Then a group of gunmen entered the compound, which is near the Afghan Public Protection Force and a government guesthouse.

An Afghan police man covers himself as smoke rises from the site of an attack in Kabul on Monday. (Reuters)

The public protection force was the target of a similar attack by Afghanistan’s main insurgent group, the Taliban, a few years ago.

Militants have hit Western installations on various occasions in Afghanistan, and the targeting of the Iraqi mission was a rare strike against an Islamic nation. The Islamic State’s claim of responsibility did not give a motive for the attack, but the Iraqi forces earlier this month declared victory in their fight to oust the militants from the northern Iraqi city of Mosul.

The Afghan Foreign Ministry denounced the attack as “unjustifiable” and said it trampled respect for “humanitarian value.”

The attack comes a week after a Taliban suicide bomber killed nearly 30 people in a different part of Kabul. The Taliban militants have stepped up their attacks in recent weeks, killing scores of security forces and making gains in various parts of the country.

The attacks underline the fragility of the situation despite the presence of U.S. troops in the country more than 15 years since the Taliban was driven from power in Kabul.

Brian Murphy in Washington contributed to this report.