Iran has released an American student who has spent the past three years in jail on spying charges in a prisoner swap.

Xiyue Wang, a Princeton University graduate student, had been sentenced to 10 years in prison after being convicted on charges of "spying under the cover of research".

The 38-year-old had been conducting dissertation research in Iran when he was detained in 2016. US officials have denied that he is a spy.

US officials told the AP news agency that Mr Wang was spending a couple of days at a military base at Landstuhl in Germany where he would undergo medical checks.

The prisoner swap, negotiated by Switzerland, saw Iranian scientist Massoud Soleimani going in the other direction.

Tensions high as Trump approves new Iran sanctions: In pictures Show all 17 1 /17 Tensions high as Trump approves new Iran sanctions: In pictures Tensions high as Trump approves new Iran sanctions: In pictures Iran claims that in this picture released by Iran state TV, their surface-to-air missile is seen as it shoots down a US surveillance drone EPA Tensions high as Trump approves new Iran sanctions: In pictures This photo shows US RQ-4A Global Hawk unmanned surveillance drone. A drone of this model was shot down by Iran on Thursday 21 June AFP/Getty Tensions high as Trump approves new Iran sanctions: In pictures An oil tanker is on fire after it was subject to a suspected attacked at the Gulf of Oman on June 13. The US has blamed Iran for the attack Reuters Tensions high as Trump approves new Iran sanctions: In pictures Iran claims that in this picture released by Iran state TV, debris from the downed US drone is seen after it was recovered from Iranian waters AFP/Getty Tensions high as Trump approves new Iran sanctions: In pictures Smoke billows from an oil tanker after it was subject to a suspected attacked at the Gulf of Oman on June 13 Reuters Tensions high as Trump approves new Iran sanctions: In pictures US President Trump holds up a signed executive order to increase sanctions on Iran on 24 June AP Tensions high as Trump approves new Iran sanctions: In pictures Iranian President Rouhani stated in a televised address that the White House is "afflicted by mental retardation" following the increase in sanctions on 25 June EPA Tensions high as Trump approves new Iran sanctions: In pictures An Iranian navy boat tackles the fire on the Norwegian owned Front Altair oil tanker after it was hit in a suspected attack AFP/Getty Tensions high as Trump approves new Iran sanctions: In pictures Iran claims that in this picture released by Iran state TV, debris from the downed US drone is seen after it was recovered from Iranian waters AFP/Getty Tensions high as Trump approves new Iran sanctions: In pictures Smoke billows from an oil tanker after it was subject to a suspected attacked at the Gulf of Oman on June 13 Reuters Tensions high as Trump approves new Iran sanctions: In pictures A screenshot from a video released by the US Department of Defense that the US claims to show Iranian removing an unexploded limpet mine form the hull of the Japan-owned ship that was attacked in the Gulf of Oman on June 13 Getty Tensions high as Trump approves new Iran sanctions: In pictures An item reportedly found on the Japan-owned oil tanker that was attacked on June 13 in the Gulf of Oman AFP/Getty Tensions high as Trump approves new Iran sanctions: In pictures A handout photograph from the US Department of Defense shows a composite material that the US claim was left behind on the hull of the Japan-owned oil tanker following the removal of an unexploded limpet mine Getty Tensions high as Trump approves new Iran sanctions: In pictures A view from the cabin of an Iranian navy boat as it tackles the fire on the Norwegian owned Front Altair oil tanker after it was hit in a suspected attack EPA Tensions high as Trump approves new Iran sanctions: In pictures Release by US government A picture released by U.S. Central Command shows damage to the hull of the oil tanker Kokuka Courageous. The picture suggests that the ship is 'likely' to have been hit by a mine as the US Secretary of State Mike Pompeo moves to blame Iran for the suspected attack Reuters Tensions high as Trump approves new Iran sanctions: In pictures Smoke billows from an oil tanker after it was subject to a suspected attacked at the Gulf of Oman on June 13 Reuters Tensions high as Trump approves new Iran sanctions: In pictures Release by US government A picture released by U.S. Central Command shows damage to the hull of the oil tanker Kokuka Courageous. The pictures suggests that the ship is 'likely' to have been hit by a mine as the US Secretary of State Mike Pompeo moves to blame Iran for the suspected attack EPA

Mr Soleimani, an expert in stem cells, was arrested at Chicago airport in 2018 and charged with attempting to violate US sanctions on Iran by exporting biological materials.

US authorities said that he had been due to be freed under the terms of a plea agreement next month.

Massoud Soleimani, right, with Iranian foreign minister Javad Zarif following his release from US custody in a prisoner exchange (Iranian Foreign Ministry) (Iran foreign minister’s office)

Hua Qu, Mr Wang's wife, said: "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.

"We are thankful to everyone who helped make this happen."

In a statement, Donald Trump said: "After more than three years of being held prisoner in Iran, Xiyue Wang is returning to the United States.

"A Princeton University graduate student, Mr Wang had been held under the pretence of espionage since August 2016. We thank our Swiss partners for their assistance in negotiating Mr Wang's release with Iran.

"The highest priority of the United States is the safety and well-being of its citizens. 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."

The prisoner swap comes despite worsening relations between Washington and Tehran since Mr Trump came to power, including the United States' unilateral withdrawal from the 2016 nuclear deal.

At least 208 killed in protests across Iran, says Amnesty

Iran continues to hold British citizens including dual national Nazanin Zaghari-Ratcliffe.

The Iranian foreign minister, Javad Zarif, met Mr Soleimani in Switzerland. He tweeted: "Glad that Professor Massoud Soleimani and Mr Xiyue Wang will be joining their families shortly. Many thanks to all engaged, particularly the Swiss government."