An American graduate student who was held in an Iranian prison for more than three years was finally headed home Saturday after a prisoner swap between the two countries.

Xiyue Wang, 38, was released in Switzerland in exchange for Iranian citizen Massoud Soleimani, who was being held in an Atlanta jail over accusations he violated U.S. sanctions.

"We thank our Swiss partners for their assistance in negotiating Mr. Wang’s release with Iran," said President Donald Trump in a statement confirming the news.

From left, U.S. Special Representative Brian Hook stands next to freed U.S. prisoner Xiyue Wang, who has been held in Iran for 3 years. State Department

"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."

Iranian Foreign Minister Mohammad Javad Zarif posted on Twitter early Saturday ahead of the swap, and again after it was confirmed.

A senior administration official told NBC News that the Swiss took the lead in the negotiations over the past three to four weeks. Those discussions for the release of Wang, a Chinese-born naturalized American citizen and a fourth-year doctoral student of history at Princeton University, came without pre-conditions on issues such as ending the Iranian nuclear program or its long-range ballistic missile program, the official said.

Wang was arrested in August 2016 while carrying out research on Iran’s Qajar dynasty for his Ph.D., according to the university, his wife and the U.S. government.

He was convicted of two counts of espionage in April 2017 and sentenced to ten years imprisonment. He had been held in Evin Prison, the Tehran facility that houses most of the country's political prisoners.

Iran released video in November 2017 of Wang allegedly trying to smuggle documents. Then-State Department spokesperson Heather Nauert explicitly denied Wang was working on behalf of any U.S. government agency.

The U.S. had repeatedly called for his release. In his statement Saturday, Trump said he "had been held under the pretense of espionage."

His wife, Qu Hua, had worked with Princeton trying to win his release. She told NBC News in November 2017 that Wang was struggling with depression in prison.

He was also missing out on watching their son grow up, she said, having last seen the boy when he was only 2 years old.

"My son told his teacher that, 'When I grow up, my daddy will come home.'"

After the news that he would do just that this weekend, Qu said in a statement that "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," she said.

"The entire Princeton University community is overjoyed that Xiyue Wang can finally return home to his wife and young son, and we look forward to welcoming him back to campus," said Princeton President Christopher L. Eisgruber.

Wang's lawyer also celebrated the news, urging both countries to "keep open a pathway."

#Xiyue, Hua & Shaofan are a remarkable young family on a new journey. Innocent, unjustly detained & for political reasons, suffered for over three years in Evin. This could've been avoided. Stakeholders on all sides should help secure the release of others and keep open a pathway pic.twitter.com/AAGoJ1UvGJ — Jason I Poblete (@JasonPoblete) December 7, 2019

A senior administration official confirmed to NBC News that Wang was flown from Tehran to Zurich, where he was met by U.S. Special Representative Brian Hook. Hook then accompanied Wang to Ramstein Air Base in Germany. He will undergo further evaluation at a local medical center before heading home.

Wang was among at least four other Americans being held by Iran, including Iranian-American father and son Siamak and Baquer Namazi, navy veteran Michael White and former FBI agent Robert Levinson.

Secretary of State Mike Pompeo said Saturday that "The United States will not rest until we bring every American detained in Iran and around the world back home to their loved ones."

"We thank the Swiss government for facilitating the return of Mr. Wang," Pompeo added, "and are pleased that Tehran has been constructive in this matter. We continue to call for the release of all U.S. citizens unjustly detained in Iran."

The effort to secure Wang’s release began to gain traction over the past several months, two sources familiar with the matter told NBC News.

Iran’s release in June of Nizar Zakka, a U.S. permanent legal resident of Lebanese descent, helped “break the ice,” one of the sources said.

Zakka said after he was freed that he believed his release was a sign that Iran was ready to negotiate for a possible prisoner exchange, and the families of Americans held in Iran shared that view.

Iran’s foreign minister had made it clear in a number of public statements that Tehran was open to the idea and Iranian state media devoted much attention to the case of Soleimani,

Soleimani, a stem-cell researcher at Tarbiat Modares University in Tehran, was on his way to perform research at the prestigious Mayo Clinic in Minnesota when he was arrested by U.S. authorities in 2018.

He was accused of violating trade sanctions by trying to export chemicals known as growth factors, which are commonly used in medical research. He was scheduled to appear in court on Wednesday.

The prisoner swap comes amid growing tensions between Iran and the U.S. and its allies in the Gulf.

The Pentagon said Thursday that the U.S. was formulating plans to potentially deploy more U.S. troops to the Middle East in response to a growing threat from Tehran.

Crushing sanctions imposed by President Donald Trump last year following the U.S. withdrawal from Tehran’s nuclear deal with world powers have left Iran facing widespread economic discontent.

Demonstrations erupted across the country recently in response to a 50 percent hike in gas prices. U.S. officials, along with human rights groups, said as many as 1,000 Iranians were killed and thousands more imprisoned since the protests began on Nov. 15.

Alireza Miryousefi, a spokesman for Iran’s mission to the United Nations, called the casualty numbers "purely speculative and highly inaccurate," while adding an investigation into the "disturbances" and "those affected, whether injured or killed" was ongoing.

Trump weighed in on the protests Tuesday, saying in a tweet that "America supports the brave people of Iran who are protesting for their freedom."