When Iran's President Mahmoud Ahmadinejad announced the release of the 15 British sailors and marines, it was his first major public intervention in the 13-day affair.
BBC Iranian affairs analyst Pam O'Toole asks who in Iran might have decided to set the group free.
Iran has many different interlocking - and sometimes competing - centres of power.
Mr Ahmadinejad was not publicly involved in the issue until it ended
At best, the decision-making process there is opaque. It is often difficult to know who makes the decisions on some issues - something which causes immense headaches for Western countries trying to negotiate with Tehran.
And although the president is democratically elected by the people, it is the supreme leader - who is not - who is allowed the final say on all matters of state.
Iran's fiery president may have announced the release of the captured Britons. But previously he had been unusually silent on the issue. A variety of different officials and departments appear to have been involved as the confrontation evolved.
In the days immediately following the arrests, it was left to Mr Ahmadinejad's foreign minister, Manouchehr Mottaki, to make statements on the issue.
As the stand-off continued, it became clear that Iran's top national security official, Ali Larijani, was playing a key role.
When Britain increased the diplomatic stakes, seeking international support for its stand from the UN Security Council and the European Union, it was Mr Larijani who spoke up, warning London of the dangers of internationalising what was essentially a bilateral issue.
And it was Mr Larijani who came to the fore again when a quieter stage of diplomacy was underway in the second week of the crisis.
He appeared on British television, where he suggested there was no need to put the sailors and marines on trial. He later held talks by phone with the chief foreign policy adviser of UK Prime Minister Tony Blair.
Ali Larijani is said to have the ear of Iran's supreme leader
Mr Larijani, best known in the West as Iran's chief nuclear negotiator, is secretary of Iran's Supreme National Security Council.
The council is in charge of all national security issues and is technically headed by President Ahmadinejad. Both men are hardline conservatives, but have very different approaches.
While Mr Ahmadinejad is often confrontational, Mr Larijani, although a tough negotiator, is more pragmatic and less abrasive. He is also said to have the ear of the most powerful individual in Iran, the supreme leader.
In recent months, as tension has built between Iran and the West over the imposition of UN sanctions on Iran because of its controversial nuclear programme, Mr Larijani has played an increasingly high-profile role.
Meanwhile, Mr Ahmadinejad has been under increasing fire from within the Iranian system for his confrontational approach, which some fear is damaging Iran's image abroad and serving to increase the international pressure on Tehran.
However, in times of national crisis, Iran's political elite does often unite and make collective decisions through the Supreme National Security Council.
The British servicemen flew back from Tehran on Thursday
It is widely believed that the council, and the supreme leader, may have come to a collective decision in this instance.
And Mr Ahmadinejad's role? As chairman of the council, he would have played a part in that decision-making process.
Some analysts have cheekily suggested that he was given the high-profile job of announcing the decision as a reward for his silence over the preceding weeks.
But, in reality, no-one outside a small, elite circle in Iran really knows.