Britain has reopened its embassy in Tehran, a striking signal of how Western ties with Iran have thawed since protesters stormed the compound nearly four years ago.

Foreign secretary Philip Hammond watched the British flag being raised in the garden of the opulent 19th century building while the national anthem played.

In 2011, the attackers burned the Union Jack and ransacked the ambassador's residence.

Key points: Iran, Britain reopen respective embassies

Iran, Britain reopen respective embassies Relations had been tense since the British embassy in Tehran was ransacked in 2011

Relations had been tense since the British embassy in Tehran was ransacked in 2011 Protests were held outside re-opening ceremonies

Protests were held outside re-opening ceremonies Iran's foreign minister says US "illogical attitude" means "situation is different"

"Today's ceremony marks the end of one phase in the relationship between our two countries and the start of a new one — one that I believe offers the promise of better," he said.

After what was a low point in diplomacy between the two countries, he said, the relationship had improved "step by step" since the election of Iranian president Hassan Rouhani in 2013.

Mr Hammond said the nuclear deal that the Islamic Republic struck with six major world powers last month was also an important milestone.

The agreement prompted a flurry of European visits — including from German and French ministers — aimed at positioning for the end of Iran's long economic isolation.

Britain had been held back by security concerns after the storming of its two main diplomatic compounds in Tehran on November 29, 2011.

The protesters slashed portraits of British monarchs, torched a car and stole electronic equipment.

Graffiti reading "Death to England" still adorns the doors to a grand reception room in a reminder of the storming.

Prime minister David Cameron called the attack a "disgrace", closed Britain's embassy and expelled Iran's diplomats from London.

On Sunday a small group of protesters reportedly gathered near the newly reopened Tehran embassy, which was guarded by dozens of Iranian security forces.

A few hours after the Tehran ceremony, Iran reopened its embassy in London — both will be run by temporary diplomats at first with ambassadors to be agreed within months, Mr Hammond said.

He is only the second British foreign minister to visit Iran since the 1979 Islamic revolution that toppled the US-backed shah — the last visit was by Jack Straw in 2003.

Iran's says situation with 'illogical' US is different

When asked if Tehran would now countenance a restoration of the US diplomatic mission, Iranian foreign minister Javad Zarif said the United States' "illogical attitude" towards Iran meant the time was not ripe for a similar move with Washington.

"It seems that there needs to be a change in that kind of attitude and behaviour on the part of the US," he said.

"So the situation is different with the US."

The US embassy was sacked in the early days of the Islamic Revolution in 1979 by students who feared a repeat of a 1953 coup, when the CIA orchestrated the overthrow of Iran's prime minister.

The ensuing US hostage crisis lasted 444 days and Washington and Tehran have yet to restore diplomatic ties.

US president Barack Obama has promised to exercise his veto if the US Congress, dominated by Republicans opposed to the deal, rejects the agreement, which would start the process of lifting a raft of sanctions which have hurt Iran's economy.

Reuters