Britain has denounced the arrest of its ambassador to Iran as a “violation of international law” as a new diplomatic row broke out between London and Tehran over anti-government protests engulfing Iran.

Boris Johnson and Angela Merkel condemned the detention of Rob Macaire, according to a spokesman from the UK prime minister’s office who issued a statement after the two leaders spoke on Sunday.

Macaire was briefly held on Saturday as anti-government demonstrations broke out in Tehran over the shooting down of a Ukrainian airliner by Iranian forces. The ambassador was accused of taking part in the protests, a claim he denies.

On Sunday Iran’s foreign ministry said it had summoned Macaire to explain himself.

Tehran said it had summoned Macaire to justify his “illegal and inappropriate presence” at the protest, despite the ambassador denying he had taken part. Meanwhile a group of pro-regime protesters gathered outside the UK embassy calling for its closure.

The latest move has threatened to further escalate the tensions between London and Tehran after the UK foreign secretary, Dominic Raab, denounced Macaire’s detention as a “flagrant violation” of international law – words which were later echoed by Johnson.

Macaire, who was released shortly after Iranian diplomatic officials learned of his arrest, tweeted that he had attended what was advertised as a vigil, left after five minutes as it began to turn into a protest, and was detained 30 minutes later as he made his way back to the embassy.

He said it was normal to wish to pay respects, adding that some of the 176 who died in the plane’s downing were British. “Arresting diplomats is of course illegal, in all countries,” he tweeted.

Rob Macaire (@HMATehran) Thanks for the many goodwill messages. Can confirm I wasn’t taking part in any demonstrations! Went to an event advertised as a vigil for victims of #PS752 tragedy. Normal to want to pay respects- some of victims were British. I left after 5 mins, when some started chanting.

Iran’s deputy foreign minister said on Sunday that Macaire had been “arrested as [an] unknown foreigner in an illegal gathering”. “When police informed me a man’s [been] arrested who claims to be UK amb[assador], I said IMPOSSIBLE!” tweeted Seyed Abbas Araghchi. “Only after my phone conversation w[ith] him I identified, out of big surprise, that it’s him. 15 mins later he was free.”

A group of protesters from the Revolutionary Guards’ Basij militia gathered outside the UK embassy to chant “death to England” and demand the embassy’s closure. The group was relatively small, but Foreign Office officials described the atmosphere as tense.

The gathering of the one-time volunteer force of the Revolutionary Guards appeared to contrast with the Iranian foreign ministry’s efforts to calm the episode down and emphasise that the ambassador was speedily released once his identity was confirmed. The Iranian ambassador to the UK, Hamid Baeidinejad, cast the episode as largely a misunderstanding, saying “the moment the police has been informed of the identity of the UK ambassador, he has been freed. Misinformation is a major source of misunderstanding and detrimental to tranquillity.”

The semi-official Tasnim news agency, which is linked to Iran’s Revolutionary Guards, said Macaire had been arrested for “organising suspicious movements and protests in front of Amirkabir University but released after hours”. It added that he would be summoned by the foreign ministry on Sunday to explain why he was provoking “radical acts amongst the protesters”.

The report claimed that an informed police source said he was using “a shop which is located in front of the main gate of Amirkabir University as the envoy’s secret place for coordination”.

A separate report said the vigil turned into a protest, which is largely the explanation given by the ambassador.

Raab said: “The arrest of our ambassador in Tehran without grounds or explanation is a flagrant violation of international law. The Iranian government is at a crossroads moment. It can continue its march towards pariah status with all the political and economic isolation that entails, or take steps to de-escalate tensions and engage in a diplomacy.

Labour’s Emily Thornberry, the shadow foreign secretary, also said Macaire’s arrest was a breach of international law. She told BBC One’s The Andrew Marr Show: “He arrived at a vigil for the 170 people, and the vigil was a genuine expression by the people of Tehran about the deep regret they felt about the Ukraine plane crash. He went off to get his hair cut and was grabbed.

“It was a complete breach of international law and it was totally wrong to do so. People under stress make bad, really profoundly bad, decisions.”

The UK was winning diplomatic support from other European countries. The German foreign ministry issued a statement saying: “Temporary detention of the UK ambassador to Tehran by Iranian security forces is a completely unacceptable violation of international law. We strongly condemn this action. Compliance with the most elementary rules of international conduct is in the interest of all.”

But some Iranian hardliners called for Macaire to be expelled from the country. In parliament, Alireza Salimi, a conservative member of the House of Representatives, said: “It is strange that the British ambassador was present in the riots last night and finally came out of the curtain; we did not know whether the British embassy building was an embassy or a chaos command centre; an embassy or counter-revolutionary organisation.”

Macaire was last week called in by the Iranian foreign ministry for an official dressing down over the way in which senior British politicians including Boris Johnson and Raab had appeared to welcomed the death of Qassem Suleimani.

• This article was amended on 13 January 2020 because an earlier version referred to the Iranian ambassador to the UK, Hamid Baeidinejad, as the UK ambassador to Iran. This has been corrected.