US president Donald Trump had rare positive words for Iran on Saturday, thanking the US foe for a “very fair” negotiation to successfully pull off a prisoner swap that saw an American released from Iranian detention amid soaring tensions.

The exchange, which took place in neutral Switzerland, involved a Princeton graduate student jailed in Iran for espionage since 2016 and an Iranian national arrested over a year ago in Chicago.

“Thank you to Iran on a very fair negotiation,” tweeted Trump, as Xiyue Wang made his way home to his family. The US leader was expected to welcome Wang in person when he arrives in the US, after a stop in Germany for medical evaluations.

“It was a one-on-one hostage swap,” Trump told reporters. “I think it was great to show than we can do something. It might have been a precursor as to what can be done.”

A photo tweeted by the US Embassy in Bern showed Wang on a rainswept tarmac in Zurich with an official blue and white US jet in the background, hugging Ambassador Edward McMullen.

The Chinese-born American was in apparent good health and in “very, very good humour”, said a senior US administration official.

Tehran had announced the release of its national, Massoud Soleimani, shortly before Trump revealed that Wang was returning home.

“Glad that Professor Massoud Soleimani and Mr Xiyue Wang will be joining their families shortly,” Iran’s Foreign Minister Mohammad Javad Zarif tweeted – along with a photograph of himself and the scientist on a plane under the words “Going home”.

“Many thanks to all engaged, particularly the Swiss government,” which has looked after US interests in Iran in the absence of diplomatic ties, Zarif said.

The Swiss foreign ministry confirmed that the exchange – which it called a “humanitarian gesture” – took place on its territory. Both the US and Iran credited Switzerland with an intensive diplomatic effort to secure the men’s release.

“Our country stands ready for further facilitation,” the foreign ministry statement said.

The US and Iran have not had diplomatic ties since 1980, and relations have sharply worsened since Trump withdrew from an international accord giving Iran sanctions relief in return for curbs on its nuclear programme.

The arch-enemies came to the brink of military confrontation in June this year when Iran downed a US drone and Trump ordered retaliatory strikes before cancelling them at the last minute.

Secretary of State Mike Pompeo said the US was “pleased that Tehran has been constructive in this matter”.

Briefing reporters on condition of anonymity, the senior US official noted that Trump “remains committed to talks with Iran without preconditions” – about Tehran’s nuclear programme, its “malign activities” in the Middle East, and the deadly mass protests that have gripped the country.

While Iran has so far rebuffed US offers of talks, the official said: “We’re hopeful that the release of Mr Wang is a sign that the Iranians may be willing to come to the table to discuss all these issues.”

The official also voiced hope that Wang’s release signals “the Iranians are realising that the practice of hostage-taking diplomacy really should come to an end”.

A doctoral candidate at Princeton, Wang was researching his dissertation on late 19th- and early 20th-century Eurasian history when he was imprisoned in August 2016. He was serving 10 years on espionage charges.

“He was not a spy . . . and was wrongfully detained from the start,” the US official said.