"The Iranian leadership does not think the US or Israel will attack them," says an Iraqi observer who was recently in Tehran. "So they feel safe in acting aggressively against Britain as a surrogate for the US."
At the same time, Iran's leaders are nervous because of the likely fall of the Syrian government, which would deprive Iran of its main ally in the Arab world. In addition, sanctions are putting pressure on Iran and the next Iranian election is likely to be peculiarly divisive.
All these factors create a mood in Tehran favourable to acting tough to show that it will not submit tamely to measures against it. Britain is an obvious target, given its closeness to the US and historic Iranian suspicions of Britain's covert role in conspiracies against the country.
This happened in 2007 when a series of tit-for-tat attacks in Iraq between Iran and the US set the stage for the seizure by Iranian Revolutionary Guards of a British naval vessel accused of entering Iranian territorial waters in the Gulf. Eight Royal Navy sailors and seven Marines were taken prisoner. This undercover war still continues with Iranian scientists being assassinated and mysterious bomb explosions at military and other facilities in Iran.
Responsibility for these acts has been attributed to Israel, reportedly acting through the Iranian opposition movement the Mojahedin-e-Khalq. The Iranian failure to respond to these attacks inside Iran has been interpreted as a sign of weakness abroad.
The Iraqis are worried that Iran will seek to compensate for the loss of its main ally by increasing its influence in Iraq. Iran already has a strong position there because of its links to the Shia religious parties, which hold power in Baghdad. The last US military forces will have departed by the end of the year.
In acting against Britain, Iran probably wants to show that states taking the lead in imposing sanctions and refusing to rule out military action will pay a price. For all the belligerent words in Israel and the US, Iraqi leaders do not think that Israel will do anything without US permission and Washington is not eager in an election year to get involved in another war in the Middle East. The US Vice President, Joe Biden, is on a three-day visit to Iraq to draw down the curtain on the US military presence in the country.