A Chinese-American detained in Iran for three years on spying charges was freed and an imprisoned Iranian was released by Washington in return, US President Donald Trump and an Iranian official said.
Mr Trump said Chinese-American Xiyue Wang was returning to the United States.
An Iranian official said that Iranian Massoud Soleimani had been freed from detention in the United States.
In a statement issued by the White House, Mr Trump made no mention of the freeing of Mr Soleimani but thanked the Swiss government for its help in negotiating Mr Wang's release.
"Freeing Americans held captive is of vital importance to my Administration, and we will continue to work hard to bring home all our citizens wrongfully held captive overseas," he said.
Iranian Foreign Minister Mohammad Javad Zarif said earlier the prisoner swap was imminent.
"Glad that Professor Massoud Soleimani and Mr Xiyue Wang will be joining their families shortly. Many thanks to all engaged, particularly the Swiss government," he tweeted.
Switzerland represents US diplomatic interests in Iran, since Washington and Tehran cut diplomatic ties shortly after the 1979 Islamic Revolution in Iran.
Hua Qu, Mr Wang's wife, welcomed her husband's release.
"Our family is complete once again. Our son Shaofan and I have waited three long years for this day and it's hard to express in words how excited we are to be reunited with Xiyue," she said in a statement.
"We are thankful to everyone who helped make this happen."
Mr Wang, a US citizen and Princeton University graduate student, was conducting dissertation research in Iran in 2016 when he was detained and accused by Iran of "spying under the cover of research," an allegation his family and the university deny.
He was subsequently convicted on espionage charges and sentenced to ten years in prison in 2017.
Prof Soleimani, a stem cell expert, was arrested at Chicago airport in October 2018 for allegedly attempting to export biological materials to Iran in violation of US sanctions on Iran over its nuclear programme.
Washington has demanded Iran release the Americans it is holding, including father and son Siamak and Baquer Namazi; Michael R White, a Navy veteran imprisoned last year, and Robert Levinson, a former FBI agent missing since 2007.
Several dozen Iranians are being held in US prisons, many of them for breaking sanctions.
Tensions have heightened between Iran and the United States since Mr Trump last year pulled Washington out of a 2015 nuclear deal between Iran and six major powers and reimposed sanctions that have crippled Tehran's economy.
In return, Iran has gradually scaled back its commitments to the agreement.