WASHINGTON — Iran on Saturday freed an American graduate student who had been imprisoned in Tehran for more than three years on suspicion of being a spy, in an exchange of prisoners at a moment of high tensions with Washington.

The American, Xiyue Wang, was flown in a Swiss government airplane from Tehran to Zurich, where he was met by Brian H. Hook, the State Department’s special representative for Iran, according to two senior United States officials.

Mr. Wang, 38, was a fourth-year Princeton University graduate student conducting research in Iran when he was arrested there in August 2016. He was charged with espionage and sentenced to 10 years in prison. United States officials deny that Mr. Wang, who had been locked in Tehran’s notorious Evin Prison, was a spy.

In exchange for Mr. Wang’s release, the United States freed Masoud Soleimani, an Iranian scientist who was arrested at a Chicago airport last year and was convicted on charges of violating American trade sanctions against Iran. The Justice Department has dropped those charges. American officials said that Mr. Soleimani’s release was a low price to pay for Mr. Wang’s freedom because Mr. Soleimani was expected to be released from prison as early as next month under a plea agreement.