A gunman stormed the Azerbaijan Embassy in Iran's capital Friday and killed its head of security.
The shooter, armed with a Kalashnikov assault rifle, also wounded two guards in the attack.
Police in Tehran said a suspect was arrested.
Tehran's police chief, General Hossein Rahimi, said the suspect was an Iranian man who believed his Azerbaijani wife was being held at the embassy.
Iranian Foreign Minister Hossein Amirabdollahian said the gunman's motive was personal.
He told Azeri Foreign Minister Jeyhun Bayramov in a phone call that he hoped the attack would not damage bilateral ties, according to Reuters.
Early reports in Iranian media said the attacker entered the embassy with two small children. However, surveillance video released in Azerbaijan, purportedly of the attack, showed the gunman entering the building alone.
It also appeared to show an Iranian security officer doing little to stop the attack.
Azerbaijan's President Ilham Aliyev called the attack a "terrorist act."
"Terror against diplomatic missions is unacceptable!" he said in a statement and called for the suspect to be swiftly investigated and punished.
Azerbaijan's Foreign Ministry accused Iran of not doing enough to secure the diplomatic post and said it would evacuate the embassy.
"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," it said.
The United States also condemned the attack.
"We echo President Aliyev's call for a prompt investigation into this unacceptable violence," said U.S. State Department spokesperson Ned Price.
Azerbaijan has had difficult diplomatic relations with Iran. The former Soviet republic is a close ally of Iran's historical rival Turkey. Azerbaijan also has friendly ties with Israel, another foe of Iran, and this month appointed its first ever ambassador to Israel.
Millions of Turkic-speaking ethnic Azerbaijanis live in Iran. The neighboring countries both belonged to the Persian Empire until the early 19th century.
Some information for this report came from The Associated Press, Reuters and Agence France-Presse.