DUBAI, United Arab Emirates (AP) - A gunman stormed the Azerbaijan Embassy in Iran's capital Friday, killing its security chief and wounding two guards in an attack that spiked long-simmering tensions between the two neighboring countries.

Azerbaijan's Foreign Ministry said it would evacuate the diplomatic post, accusing Iran of not taking reported threats against it seriously in the past that include inciting comments in hard-line media over Azerbaijan's diplomatic ties to Israel.

Tehran's police chief, Gen. Hossein Rahimi, initially blamed the attack on “personal and family problems,” something quickly repeated across Iranian state media. But within hours Rahimi would lose his position as police chief after footage emerged that appeared to show a security force member doing nothing to stop the attack.

“Previously, there have been attempts to threaten our diplomatic mission in Iran, and it was constantly raised before Iran to take measures to prevent such cases, and to ensure the safety of our diplomatic missions,” the Azerbaijan Foreign Ministry said. “Unfortunately, the last bloody terror attack demonstrates the serious consequences of not showing proper sensitivity to our urgent appeals in this direction.”

“We are of the opinion that the recent anti-Azerbaijani campaign against our country in Iran led to such attack against our diplomatic mission,” the ministry added.

Azerbaijan President Ilham Aliyev called the assault a “terrorist attack.” He identified the dead security chief as 1st Lt. Orkhan Rizvan Oglu Askarov.

“We demand that this terrorist act be swiftly investigated and the terrorists punished,” Aliyev said in a statement. “Terror against diplomatic missions is unacceptable!”

The attack happened Friday morning, the second day of the Iranian weekend. Surveillance video released in Azerbaijan purportedly showed the gunman arriving by car at the embassy, running into the back of another car parked out front. He exited his car, holding what appeared to be a Kalashnikov-style rifle.

From there, details immediately conflict with the Iranian account of the attack.

Iranian state TV had quoted Rahimi as saying the gunman had entered the embassy with his two children during the attack. However, surveillance footage from inside the embassy, which matched details of the aftermath and bore a timestamp matching the Azerbaijan Foreign Ministry's statement, showed the gunman burst through the embassy's doors alone.

Those inside tried to push through metal detectors to take cover. The man opens fire with the rifle, its muzzle flashing, as he chases after the men into the small side office. Another man bursts from a side door and fights the gunman for the rifle as the footage ends.

Another surveillance video from outside the embassy, which also corresponded to the same details, showed the gunman slam his car into another in front of the embassy. The gunman then got out and leveled his rifle at a figure inside of the Iranian police stand, likely a security force member, who stood still and did nothing as the man stormed the embassy.

Video of the aftermath showed an empty diplomatic police post just near the embassy, with one man apparently wounded in an SUV parked outside. Inside the embassy past a metal detector, paramedics stood over what appeared to be a lifeless body in a small office as blood pooled on the floor beneath.

Associated Press journalists later saw the embassy's front door pocked with bullet holes after the attack.

Iranian prosecutor Mohammad Shahriari reportedly said the gunman's wife had disappeared in April after a visit to the embassy. The Iranian judiciary's Mizan news agency quoted Shahriari as saying the gunman believed his wife was still in the diplomatic post at the time of the attack - even though it was some eight months later.

Iran's Foreign Ministry spokesman Nasser Kanaani also said his country strongly condemned the attack, which was under investigation with “high priority and sensitivity.” Azerbaijan also summoned Iran's ambassador there to lodge a protest over the attack as authorities replaced Rahimi, Tehran's police chief, without offering an explanation.

Azerbaijan borders Iran's northwest and belonged to the Persian Empire until the early 19th century. Ethnic Azeris also number over 12 million people in Iran and represent the Islamic Republic's largest minority group - making maintaining good relations even more important for Tehran.

There have been tensions between the two countries as Azerbaijan and Armenia have fought over the Nagorno-Karabakh region. Iran also wants to maintain its 44-kilometer (27-mile) border with landlocked Armenia - something that could be threatened if Azerbaijan seizes new territory through warfare.

Iran in October launched a military exercise near the Azerbaijan border, flexing its martial might amid the nationwide protests rocking the Islamic Republic. Azerbaijan also maintains close ties to Israel, which Tehran views as its top regional enemy. The Islamic Republic and Israel are locked in an ongoing shadow war as Iran's nuclear program rapidly enriches uranium closer than ever to weapons-grade levels. Israel also offered its condolences to Azerbaijan over the attack.

Turkey, which has close ties to Azerbaijan, condemned the attack, called for the perpetrators to be brought to justice and for measures to be put in place to prevent similar attacks in the future. Turkey has backed Azerbaijan against Armenia over Nagorno-Karabakh.

“Turkey, which has been subjected to similar attacks in the past, deeply shares the pain of the Azerbaijani people,” a Turkish Foreign Ministry statement said. “Brotherly Azerbaijan is not alone. Our support to Azerbaijan will continue without interruption, as it always has.”

U.S. State Department spokesperson Ned Price said the U.S. condemns the attack. “We echo President Aliyev's call for a prompt investigation into this unacceptable violence,” he said. “We offer our deepest condolences to the families and loved ones of those who were killed and injured today. Any attack against diplomats or diplomatic facilities anywhere is unacceptable.”

--

Associated Press writers Vladimir Isachenkov in Moscow, Nasser Karimi in Tehran, Iran; Suzan Fraser in Ankara, Turkey, and Matthew Lee in Washington contributed to this report.