People gather outside of the Azerbaijan Embassy after an attack there in Tehran, Iran, Friday, Jan. 27, 2023. AP
Tehran's police chief said the man who carried out the attack was motivated by "personal" reasons.
"All responsibility for the attack lies with Iran," Azerbaijani foreign ministry spokesman Ayxan Hacizada told local media.
He said a recent anti-Azerbaijani campaign in Iranian media had "encouraged the attack."
Hacizada later told Turkish TRT Haber TV station that the embassy staff "are being evacuated from Iran."
Azerbaijani President Ilham Aliyev said on Twitter: "I strongly condemn the terrorist attack".
In a statement earlier on Friday Azerbaijan's foreign ministry said "a man armed with a Kalashnikov killed the head of the diplomatic mission's guard."
It said that two guards injured by the attacker were in a "satisfactory" condition and an investigation had been launched.
The attacker has been arrested and is an Iranian man married to an Azerbaijani woman, Tehran's police chief General Hossein Rahimi said.
Iran's foreign ministry spokesman, Nasser Kanani, said Tehran strongly condemned "the armed attack... which unfortunately resulted in the death of one person".
"According to the preliminary investigation, these are personal motives," he added.
Iran is home to millions of Turkic-speaking, ethnic Azerbaijanis and it has long accused Baku of fomenting separatist sentiments in its territory.
Relations between the two countries have traditionally been sour, with the former Soviet republic a close ally of Iran's historical rival Turkey.
Tehran also fears that Azerbaijani territory could be used for a possible offensive against Iran by Israel, a major supplier of arms to Baku.