Britain's ambassador to Tehran denied Sunday that he took part in a demonstration that broke out at a memorial for the 176 people killed when a plane was shot down.
Students held a gathering at Tehran's Amir Kabir University on Saturday evening to honour those killed hours after Iran admitted the Ukrainian airliner was downed by mistake.
Iran's Mehr news agency said the ambassador, Rob Macaire, was arrested for his alleged "involvement in provoking suspicious acts" at the gathering in front of the university.
On Sunday, Iran confirmed his arrest as a foreigner at "an illegal gathering", but said he was released soon after being identified.
"Can confirm I wasn't taking part in any demonstrations! Went to an event advertised as a vigil for victims of #PS752 tragedy," Macaire said on Twitter, adding he had been detained half an hour after leaving the area.
"Normal to want to pay respects -- some of victims were British. I left after 5 mins, when some started chanting," he said.
"Arresting diplomats is of course illegal, in all countries," he added.
Iran's deputy foreign minister on Sunday confirmed Macaire had been arrested but said he was freed soon after being identified.
"He wasn't detained, but arrested as unknown foreigner in an illegal gathering," Seyed Abbas Araghchi tweeted, adding Macaire was released 15 minutes after he called the British diplomat to confirm his identity.
The British government said Macaire was arrested and detained briefly in the Iranian capital in what it called a "flagrant violation of international law".
Iran's armed forces said on Saturday the Ukraine International Airlines Boeing 737 was mistakenly shot down, after denying for days Western claims it was brought down by a missile.
Police dispersed students who chanted "radical" and "destructive" slogans when the tribute to those killed in the air disaster turned into an angry demonstration, Fars news agency reported.