Azerbaijan will evacuate embassy staff and family members from Iran on Sunday, the foreign ministry said, two days after a gunman shot dead a security guard and wounded two other people in an attack Baku branded an "act of terrorism".
Police in Tehran have said they had arrested a suspect and Iranian authorities condemned Friday's incident, but said the gunman appeared to have had a personal, not a political, motive.
After the attack, the Azeri foreign ministry said it summoned Iran's ambassador in Baku to demand justice and would evacuate embassy staff from Tehran.
It gave no further details, including whether the embassy would continue to function.
Earlier, the ministry said the shooting was the result of Tehran failing to heed its calls for better security.
CCTV footage obtained by Reuters showed the attacker forcing his way into the embassy building and shooting at two men before a third embassy employee grapples him away.
A grey-haired man identified as the attacker was later shown on Iranian state TV saying he had acted to secure the release of his Azeri wife who he believed was being held at the embassy.
A young woman identified as the man's daughter said her mother was in Azerbaijan.
Iranian President Ebrahim Raisi called for "a comprehensive investigation" of the incident and sent his condolences to Azerbaijan and the dead man's family, state media said.
There have been tensions between the two countries as Azerbaijan and Armenia have fought over the Nagorno-Karabakh region.
Iran in October launched a military exercise near the Azerbaijan border. Azerbaijan also maintains close ties to Israel, which angered Tehran.