Britain has condemned the arrest of the UK ambassador to Iran as a "flagrant violation of international law".
Rob Macaire was detained for a short time on Saturday night after attending a vigil for those who died when Iran's military shot down a passenger plane.
He left the vigil when it turned into a protest but was later accused of helping to organise the demonstrations.
Iran said he was "an unknown foreigner in an illegal gathering" and summoned him to the foreign ministry on Sunday.
In a statement, Iran's foreign ministry said Mr Macaire was "reminded" that his presence at "illegal gatherings contravened" the Vienna Convention on diplomatic relations.
BBC diplomatic correspondent James Landale said Mr Macaire was understood to have protested strongly that his detention was unjustified.
Our correspondent says Mr Macaire made clear any suggestion that he was involved in demonstrations was completely untrue, and he was attending an event advertised as a vigil for the victims of Wednesday's crash - which killed 176 people, including four Britons.
Earlier, Iran's deputy foreign minister Seyed Abbas Araghchi, who denied Mr Macaire was detained, said in a tweet that he thought it "impossible" when police first told him that the UK ambassador had been arrested.
A phone conversation confirmed Mr Macaire's identity and he was released 15 minutes later, Mr Araghchi added.
Mr Macaire has denied taking part in protests and Foreign Secretary Dominic Raab condemned his arrest.
He was arrested and held for three hours when he stopped at a barber shop for a haircut on his way back to the UK embassy.
In a tweet the ambassador said he was attending the vigil because it was "normal to want to pay respects", adding that some of the victims were British.
The ambassador added: "Arresting diplomats is of course illegal, in all countries."
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.— Rob Macaire (@HMATehran) January 12, 2020
Prime Minister Boris Johnson and German Chancellor Angela Merkel condemned Mr Macaire's arrest in a joint statement following a phone call on Sunday, in which they discussed their "shared interests in ensuring Iran never acquires a nuclear weapon".
And Security Minister Brandon Lewis said on Sunday that the UK ambassador's arrest was "totally unacceptable" and a breach of the 1961 Vienna Convention.
"Iran does need to step back from that kind of activity and play a proper part in working with partners to de-escalate," Mr Lewis told Sky's Sophy Ridge.
Under the convention, diplomats cannot be detained. The Foreign Office is to demand a full explanation.
In a statement issued on Saturday night Mr Raab added: "The arrest of our ambassador in Tehran without grounds or explanation is a flagrant violation of international law.
"The Iranian government is at a cross-roads moment. It can continue its march towards pariah status with all the political and economic isolation that entails, or take steps to deescalate tensions and engage in a diplomatic path forwards."
The Iranian Etemad newspaper shared a picture of the ambassador on Twitter after the Tasnim news agency reported his arrest.
Protesters had taken to the streets in Iran's capital, Tehran, to vent anger at officials, calling them liars for having denied, then admitting, shooting down a Ukrainian passenger plane.
Iran had initially denied responsibility for the plane crash, but on Saturday, President Hassan Rouhani admitted Iranian military had "unintentionally" shot down the passenger plane after mistaking it for a cruise missile when it turned towards a sensitive military site.
President Rouhani said the missile strike was an "unforgivable mistake".
The crash came just hours after Iran carried out missile strikes on two airbases housing US forces in Iraq.
Mr Johnson said Iran's admission was an "important first step" and called for an investigation into the "tragic accident".
And writing in the Sunday Telegraph, Mr Raab said it was time for Tehran "to come to the negotiating table to resolve all of Iran's issues of international concern."
He said Iran "must stop pursuing a nuclear weapon, end its support for terrorism, and release the foreign nationals and dual nationals it cruelly holds".
Labour leader Jeremy Corbyn said the shooting down of the passenger plane by Iran was "an appalling act, and part of a whole pattern of appalling acts all across the region".
The Queen has also sent a message of condolence to the Governor-General of Canada - where the majority of the passengers on the flight were headed.
Out of the 176 victims on board the Kyiv-bound flight, 138 had listed Canada as their eventual destination.
The Queen said she and the Duke of Edinburgh were "deeply saddened by the tragic loss of life".
The Prince of Wales and the Duchess of Cornwall added their condolences, saying they were "utterly horrified" by the disaster.
Four Britons were on board the Ukrainian passenger plane.
Three have been named as Mohammed Reza Kadkhoda Zadeh, who owned a dry cleaners in West Sussex, BP engineer Sam Zokaei from Twickenham, and PhD student and engineer Saeed Tahmasebi, who lived in Dartford.
Mr Tahmasebi's Iranian wife, Niloufar Ebrahim, was also listed as a passenger on the plane.