Iran has summoned the UK ambassador as hardline militia members mass outside the British embassy in Tehran.
The British ambassador to Iran earlier denied taking part in anti-government demonstrations after he was held by Iranian authorities during protests over a fatal plane crash.
Iranian authorities detained Rob Macaire on Saturday on suspicion of organising, provoking and directing radical actions, but an Iranian news agency later said he had been summoned over his attendance at an "anti-government rally".
It comes as members of Iran's Basij militia, which is affiliated with Iran's elite Revolutionary Guard, gathered outside the UK embassy in Tehran demanding it be closed, according to Iranian state media.
Video footage shows a large group assembled around a small truck with speakers erected on its roof, many of whom are holding placards written in Farsi and pictures of assassinated General Qassem Soleimani.
Meanwhile, riot police and plainclothes officers have moved into Tehran's Vali e Asr Square in large numbers amid calls for further anti-government protests.
That prompted US president Donald Trump to tweet: "To the leaders of Iran - DO NOT KILL YOUR PROTESTERS. Thousands have already been killed or imprisoned by you, and the World is watching. More importantly, the USA is watching. Turn your internet back on and let reporters roam free! Stop the killing of your great Iranian people!"
On Saturday, riot police fired tear gas at thousands of Iranians who had taken to the streets to direct their anger at Supreme Leader Ali Khamenei, hours after the country's Revolutionary Guard admitted shooting down a Ukrainian passenger plane near the capital.
Mr Macaire said he visited the scene to take part in a vigil for the 176 victims who died when Iran brought down Ukrainian International Airlines flight PS752 on Wednesday with a missile it said was fired in error.
Mr Macaire tweeted in Farsi and in English: "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.
"Detained half an hour after leaving the area. Arresting diplomats is of course illegal, in all countries."
The largest share of the 176 people aboard the flight who died were Iranians, many with dual citizenship, 57 were Canadian and four were British.
Iran has issued visas to a team of Canadian officials to visit the crash site and they are expected to begin their work there on Tuesday, according to Canadian foreign minister Francois-Philippe Champagne.
Later on Sunday, deputy foreign minister of Iran Seyed Abbas Araghchi responded, also on Twitter.
He said: "He wasn't detained, but arrested as unknown foreigner in an illegal gathering. When police informed me a man's arrested who claims to be UK Amb, I said IMPOSSIBLE! only after my phone conversation w him I identified, out of big surprise, that it's him. 15 min later he was free."
Earlier, a large black banner was unveiled in Vali e Asr Square bearing names of those who died in the crash.
Overnight, Iranian protesters and newspapers piled pressure on the country's leadership.
Iran's moderate Etemad newspaper wrote in a banner headline on Sunday "Apologise and resign", adding the "people's demand" was that all those responsible for mishandling the plane crisis should quit.
Ayatollah Khamenei, the highest authority in the country, expressed "deep sympathy" to the victims of the plane crash on Saturday but did not apologise, leaving that to other senior officials.
Some officials laid the blame partly at the door of the US, after it heightened US-Iran tensions by assassinating one of Gen Soleimani, one of Iran's top military leaders.
Supreme Leader Khamenei later called for increased cooperation between countries in the Middle East to reduce tensions in the region, and blamed the problems on the US.
His official website stated: "The situation in the region is inappropriate because of the United States and its friends, and the only way to deal with it is to rely on inter-regional cooperation."
The US had previously withdrawn from Tehran's nuclear deal with world powers and then re-imposed sanctions that have gradually crippled the Iranian economy.
Britain, France and Germany have all said they remain committed to the deal, and called on Iran to stick to its terms and refrain from further violence.
In a statement released by the office of French President Emmanuel Macron, the leaders of the three countries said: "We urge Iran to reverse all measures inconsistent with the agreement and return to full compliance.
"We call on Iran to refrain from further violent action or proliferation, and we remain ready to engage with Iran on this agenda in order to preserve the stability of the region."
A commander in the Revolutionary Guard said an air defence operator had mistaken the Ukrainian passenger jet for a cruise missile after Iran retaliated for the airstrike on Gen Soleimani by hitting US bases in the region.
While the commander apologised, he added to public anger by saying he told the authorities on the day of the crash a missile hit the plane - three days before the military admitted they had shot it down.
Secretary of Iran's top national security body, Ali Shamkhani, responded on Sunday saying Iran had no intention to conceal the cause of the crash as "its nature and technical characteristics ... make it virtually impossible to conceal".
Criticism of the authorities in Iran is not unheard of, but it tends to stay within narrow limits.
The latest protests come weeks after Iran faced the country's bloodiest unrest since the 1979 Islamic revolution, with dozens said to have been killed.
Saturday's demonstrations were not limited to Tehran, with major cities such as Shiraz, Isfahan, Hamedan and Orumiyeh seeing similar action on the streets.