The British envoy was briefly detained in the Iranian capital on Saturday and accused of helping to organise unlawful protests after the Iranian government acknowledged its responsibility for accidentally shooting down a Ukrainian airliner amid fears of war with the US.

UK Ambassador to Iran Rob Macaire departed Tehran Tuesday night by airplane via the Qatari capital of Doha, IRIB news agency correspondent Ameneh Sadat Zbihpour has reported.

The news comes a day after Iranian judicial spokesman Gholam Hossein Ismaili said Tehran was considering expelling the ambassador, saying the Iranian people “and the international community expect[ed] him to be expelled from the country”.

Macaire raised the ire of Iranian officials on Saturday after being spotted at an unauthorised protest in Tehran in reaction to the country's admission that the Revolutionary Guards air defence troops had accidentally shot down a Ukrainian aircraft, mistaking it for an incoming US missile amid tensions with Washington over the assassination of a senior Iranian general.

The British ambassador denied taking part in any protests, saying Sunday that he came to “pay respects” to the victims of the plane crash, and reporting that he had left the scene after five minutes.

But Iranian media later released footage Monday purporting to show the envoy attending the protest, surrounded by a mob of unidentified individuals.

Macaire was detained by Iranian authorities for several hours, with Iran calling his actions “completely” unacceptable. The British Foreign Office blasted Tehran over the arrest, calling Macaire’s detention a “flagrant violation of international law,” and summoning Iran’s ambassador to the UK. The US State Department called on the Iranian “regime” to “formally apologise to the UK.”

On January 8, a Kiev-bound Ukraine International Airlines Boeing 737 with 176 people on board was accidentally shot down by an Iranian anti-air missile shortly after departure from Tehran. Following an internal investigation, Iran’s Revolutionary Guard admitted their responsibility for the plane’s destruction, saying they had confused it with a hostile cruise missile in anticipation of US retaliation to Iran’s missile attack against US military bases in Iraq. The missile strikes were a response to the assassination of Revolutionary Guard Quds Force commander Qasem Soleimani in a US drone strike in Baghdad on January 3. On Tuesday, Iranian President Hassan Rouhani called the plane crash a “tragic event,” promising a thorough investigation, and pledging that all those responsible would be punished.