TEHRAN — Iran freed four Americans of Iranian descent from prison on Saturday, including a Marine veteran and a reporter from The Washington Post, in a delicately negotiated swap with the United States, which released seven Iranians who had been held on sanctions violations.
Word of the prisoner exchange came just before longstanding economic sanctions on Iran were lifted under terms of the historic nuclear deal reached in July, which Iran hopes will help end its prolonged isolation.
The exchange, first reported by Iran and confirmed hours later by Obama administration officials, removed a big source of irritation between the two countries, whose relationship broke down more than three decades ago, during the 1979-1981 Tehran hostage crisis.
Obama administration officials, sensitive to criticism that they have capitulated to Iran on many issues, attributed the break in the prisoner dispute to a climate of diplomacy they had cultivated with Iran through the nuclear negotiations.
“They understood this was a priority for us, and that we’d never give it up,” said a senior administration official, speaking on the condition of anonymity because the prisoner exchange was handled with extraordinary caution. “We consistently said it was independent from the nuclear negotiations but of great importance to us.”
Families and supporters of the released Americans — Amir Hekmati, Jason Rezaian, Saeed Abedini and Nosratollah Khosravi, whose incarceration had not been publicly reported — reacted with a mix of joy and caution, reflecting the tensions and mistrust built up over Iran’s intentions toward the prisoners, who had not yet left Iran by Saturday evening.
Mr. Rezaian, a 39-year-old Californian who became Post bureau chief in Tehran in 2012, had been languishing in the city’s Evin Prison since July 2014 on vaguely defined charges of espionage that he denied and that his lawyer said had fallen apart at a closed trial in Tehran’s Revolutionary Court.
Mr. Rezaian was convicted in September, but there was never any word on his punishment. The Post and others described his prosecution as an absurdity and embarrassment for Iran.
“We couldn’t be happier to hear the news that Jason Rezaian has been released from Evin Prison,” said Frederick J. Ryan Jr., The Post’s publisher. “Once we receive more details and confirm Jason has safely left Iran, we will have more to share.”
The family of Mr. Hekmati, a 32-year-old Marine veteran from Flint, Mich., was similarly measured. “There are still many unknowns,” the family said in a statement. “At this point, we are hoping and praying for Amir’s long-awaited return.”
Hints that Mr. Hekmati might be released surfaced this month when Iranian officials permitted him to leave prison for treatment for swollen lymph nodes. The family had grown increasingly despondent because Mr. Hekmati’s father, Ali, has terminal brain cancer, and the family feared he would die before Mr. Hekmati was freed.
Naghmeh Abedini, the wife of Mr. Abedini, said in a phone interview that she first suspected some news when she heard that her husband, a 35-year-old pastor from Boise, Idaho, had been moved from prison by Iran’s intelligence police. State Department officials confirmed it to her by telephone.
“I told my kids that Daddy was coming home,” she said.
American officials also disclosed for the first time that another American, whom they identified as Matthew Trevithick, had been detained by the Iranian authorities in recent months and that he had been permitted to leave Iran. They described him as a student but shared no further information.
Mr. Trevithick’s family said in a statement that he had been detained for 40 days at Evin Prison after going to Iran for language study in September. They said he was a co-founder of SREO, a Turkey-based research center that focuses on humanitarian issues in the region.
Around the time he was arrested, Mr. Trevithick appeared on Dec. 9 on an episode of “Sources and Methods,” a podcast for researchers that he helps host. He explained that he had been absent from previous episodes because he was in Tehran for a Farsi language program. His family said Saturday that he was there to study Dari, a language closely related to Farsi that he learned over four years he spent living in Afghanistan.
American officials said they were still working to free Siamak Namazi, an Iranian-American business consultant who worked for a United Arab Emirates-based oil company and was seized in Tehran in mid-October.
Nearly all of the negotiations took place in Geneva, American officials said, and arrangements for the departure of those freed in Iran had been done by Switzerland, which attends to American interests in Iran in the absence of diplomatic relations.
The American officials described the released Iranians as convicts or suspects in sanctions violations — offenses that Iran’s government has never recognized as legitimate. They also said that as part of the negotiations, the Americans had rescinded international arrest warrants on 14 other Iranians suspected of sanctions violations.
The Iranians had originally presented a much longer list of Iranian prisoners they wanted freed, one senior official said, and “we whittled down the list to exclude anyone for crimes related to violence or terrorism.”
They reported no progress on longstanding efforts to find out more information about Robert A. Levinson, a retired F.B.I. agent who went missing near Iran’s Kish Island nearly nine years ago. “He is not going to appear as part of this deal,” said one official, who added that the Iranians had committed to “continue to seek information on his whereabouts.”
Most of the Republican presidential candidates have been critical of the overall Iran deal. On Saturday, several of them praised the release of the American prisoners but continued to attack the agreements with Iran.
Senator Marco Rubio of Florida and Gov. Chris Christie of New Jersey said President Obama should not be negotiating with Iran.
Donald J. Trump said in Portsmouth, N.H., that he was “happy they’re coming back” but that Iran had gotten the better of the deal.