Five Americans jailed for years in Iran and widely regarded as hostages are on their way home to the United States.
The last pieces in a controversial swap mediated by Qatar fell into place when $6bn (£4.8bn) of Iranian funds held in South Korea reached banks in Doha.
It triggered the departure of the four men and one woman in Tehran, who are also Iranian citizens, on a chartered flight to Qatar's capital.
They were met by senior US officials and are now on their way to Washington.
The Americans include 51-year-old businessman Siamak Namazi, who has spent nearly eight years in Tehran's notorious Evin prison, as well as businessman Emad Shargi, 59, and environmentalist Morad Tahbaz, 67, who also holds British nationality.
The US has said its citizens were imprisoned on baseless charges for political leverage.
In the first indication a deal was reached, they were moved in mid-August from Evin to a safe house in Tehran.
Five Iranians imprisoned in US jails, mainly on charges of violating US sanctions, are also being granted clemency as part of this swap. Not all of them are expected to return to Iran.
They have been named by Iran as Reza Sarhangpour, Kambiz Attar Kashani, Kaveh Lotfolah Afrasiabi, Mehrdad Moein Ansari and Amin Hasanzadeh.
"Today, five innocent Americans who were imprisoned in Iran are finally coming home," US President Joe Biden said after their plane landed in Doha.
He said all five had endured "years of agony, uncertainty, and suffering."
Mr Biden also announced fresh US sanctions targeting the former Iranian president Mahmoud Ahmadinejad and the Iranian ministry of intelligence for what he said was their involvement in wrongful detentions.
Siamak Namazi said in a statement: "I would not be free today, if it wasn't for all of you who didn't allow the world to forget me.
"From the bottom of my heart, thank you. Thank you for being my voice when I could not speak for myself and for making sure I was heard when I mustered the strength to scream from behind the impenetrable walls of Evin Prison."
He also praised President Biden for making "some incredibly difficult decisions to rescue us" and "ultimately putting the lives of American citizens above politics".
The deal comes after months of indirect talks mediated by Qatar, which began in February last year.
A source said that there were at least nine rounds of discussions in Doha. Senior Qatari officials also shuttled between Tehran and Washington.
"I think there's a little bit of a win for both sides," Iranian-born Professor Mehran Kamrava, who now teaches at Georgetown University in Qatar, told the BBC.
"For Biden, heading into the election, he's bringing Americans home and for Iran, there's the release of Iranians in prison in the United States, but it's that six billion [dollars] that's a big win."
Iranian officials have repeatedly declared they will spend their money as they wish. But sources involved in this process insist these funds will be strictly controlled.
"No funds will go into Iran," they emphasised. "Only humanitarian transactions, including food, medicine, agriculture, paid to third party vendors, transaction by transaction."
Sources told the BBC this money was not part of Iranian assets frozen by sanctions. The money in South Korea, revenue from Iranian oil sales, had been available to Tehran for bilateral and non-sanctioned aid, but was not spent for various reasons including difficulties of currency conversion.
Leading US Republicans have denounced the deal as a ransom payment and sanctions relief. The Republican chairman of the House Foreign Affairs Committee, Michael McCaul, castigated the US government for transferring funds to "the world's top state sponsor of terrorism".
Who are the American prisoners?
Morad Tahbaz: Arrested in 2018 along with eight other Iranian conservationists. They had been using cameras to track critically-endangered wild Asiatic cheetahs, but were accused of spying. Denied the charge but sentenced to 10 years in prison
Siamak Namazi: Dubai-based oil executive arrested in 2015. His elderly father, Baquer, was detained the following year, after Iranian officials allowed him to visit his son. Both sentenced to 10 years in prison for "co-operating with a foreign enemy", which they denied. Iran let Baquer leave for medical treatment in 2022
Emad Shargi: Detained in 2018 while working for an Iranian venture capital fund. Released on bail and later told he had been cleared of spying charges. Informed by a court in 2020 that he had been convicted in absentia and sentenced to 10 years in prison. Released ahead of an appeal and reportedly detained in 2021 while trying to cross Iran's western border illegally
The two others wish to remain anonymous
The enormous relief that some prisoners are finally coming home is tempered by the knowledge that more may be seized in future. There are still other dual nationals behind bars in Tehran.
"The Iranian government has become a hostage-taking government," said Sanam Vakil, director of the Middle East and North Africa programme at Chatham House, a London-based think tank. "They have been using people as pawns, and that's part of their leverage against the West."
Qatar is hoping this rare co-operation will help to catalyse progress on other long-standing disputes. This includes the 2015 nuclear deal, which many regard as dead due to the decision by then-US president, Donald Trump, to withdraw five years ago.
He said that Iran would continue to maintain strategic enmity with the United States for as long Supreme Leader Ayatollah Ali Khamenei remains in power.
President Biden has long been urged to bring the Americans home.
Earlier this year, Siamak Namazi wrote to him from an Iranian prison. Mr Namazi, who the US said was unjustly detained, described himself as having the "unenviable title of the longest held Iranian-American hostage in history".
Morad Tahbaz and his family were also left feeling angry and abandoned after receiving assurances from the British government that he would return to Britain last year along with two other British-Iranians who were detained arbitrarily, Nazanin Zaghari-Ratcliffe and Anoosheh Ashoori.