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.