The Washington Post via Getty Images Ali Rezaian, the brother of imprisoned Washington Post journalist Jason Rezaian (shown in the poster), gives reporters an update on his brother's case at the National Press Club in Washington, D.C., on July 22, 2015. Rezaian is one of four Americans expected to be freed Saturday as part of a deal with Iran.

VIENNA, Austria -- A Swiss plane carrying American citizens, including a Washington Post reporter, who were released from Iranian prison on Saturday departed Tehran Sunday. The prisoners were freed as part of a prisoner release deal between the U.S. and Iran. The agreement is the result of 14 months of high-stakes secret negotiations between the two traditional adversaries.

On Saturday, the International Atomic Energy Agency issued a report confirming Iran's compliance with the July 2015 nuclear agreement between Iran, the U.S. and five world powers -- a move that triggered broad sanctions relief. As part of the prisoner exchange, the U.S. is releasing or dropping charges against seven Iranians who were being held in the country on sanctions violations. All were born in Iran, but six are dual Iranian-American citizens. The seven men all have the option to remain in the U.S. The U.S. is also dropping Interpol red notices against 14 Iranians who they assessed were not likely to be extradited to the U.S. regardless.

The agreement will free four Americans who have been imprisoned in Iran for years on trumped up charges, or in some cases no charges at all: Washington Post Tehran correspondent Jason Rezaian, former U.S. Marine Amir Hekmati, Christian pastor Saeed Abedini, and Nosratollah Khosrawi-Roodsari. The imprisonment of Khosrawi-Roodsari has never been previously reported. Matthew Trevithick, an American student who was held in Iran for 40 days, was also released on Saturday, but not as part of the negotiated agreement between Iran and the U.S.

“I’m very happy to say that as we speak, we have received confirmation that five Americans that had been unjustly detained in Iran have been released from custody and should be on their way home to their families before long," Secretary of State John Kerry said Saturday evening in Vienna. A U.S. official confirmed Sunday morning that the former prisoners who wished to depart Iran had left.

Saturday marked a whirlwind of events for Iranian-American diplomacy.

After the IAEA issued the report confirming Iran's compliance with the nuclear deal, Kerry signed a waiver lifting congressionally enacted sanctions related to Iran's nuclear program. At the same time, President Barack Obama issued a new executive order to lift sanctions that were enacted under his authority, and the U.N. and EU moved to provide sanctions relief to Iran.

Kerry was expected to then fly to the site where the Americans will be released to welcome them. But the plane bearing the released prisoners left Tehran much later than originally planned, and Kerry instead flew back to Washington on a red-eye. The Treasury Department is likely to announce new sanctions against 11 people and entities tied to Iran’s ballistic missile program soon -- just after lifting sanctions related to Iran’s nuclear program.

Rezaian's mother and wife, who live in Iran, found out about his release in advance and are on the flight out of Tehran. U.S. officials, who say they did not tell the Rezaians the exchange was imminent, had planned to notify all of the families of the prisoners once the plane took off for Tehran -- and after they were certain the agreement wouldn't collapse.

The transfer of the American prisoners back into U.S. custody was originally planned to occur in Bern, Switzerland, but may now occur at a different location due to weather concerns.

After the transfer, the four Americans will be taken to the Landstuhl Regional Medical Center, an American military hospital in Germany, for immediate medical treatment before returning home.

Another Iranian-American, Siamak Namazi, was not included in the prisoner deal and remains imprisoned in Iran. "We won't give up" on Namazi, the administration official said." Another American, Robert Levinson, disappeared on Iran’s Kish Island in 2007, where he was doing unofficial work for the CIA, but Iranian officials deny having knowledge of his whereabouts. "The case of Robert Levinson ... was aggressively pursued through this channel and through this process," the official said. "In the end, he did not go into this deal, but we have an arrangement with the Iranians ... and they will continue to seek information about his whereabouts."

Saturday's announcement comes after 14 months of negotiations between American and Iranian diplomats, some of whom were already meeting regularly to negotiate the nuclear deal.

The State Department never publicly disclosed the existence of negotiations to free the Americans and publicly rejected calls to tie the prisoners -- or any other issue -- to the nuclear talks. But privately, Brett McGurk, who until recently was deputy secretary of state for Iran and Iraq, led talks focusing on the prisoners.

Kerry and Iranian Foreign Minister Mohammad Javad Zarif, the public faces of the nuclear deal negotiations, also spoke in private about the prisoners. Kerry and Zarif deliberately kept the talks separate from the nuclear negotiations, never raising the two topics in the same meeting, according to a a second senior administration official. Kerry, faced with resistance to the deal at home and in Iran, kept the discussions alive at several critical moments, the second senior official said.

McGurk, who is better known for his current role as the U.S. special envoy for the coalition fighting the Islamic State, is also known within the State Department as a skilled negotiator who worked with Iranian officials during his extensive time in Iraq. He was also able to fly under the radar throughout months of negotiations with the Iranians, a feat that would have been more difficult for Kerry.

Despite the appearance a "grand plan," the prisoner deal was not tied to the nuclear deal implementation day, the second administration official said.

JOE KLAMAR via Getty Images Sarah Hekmati, the sister of Amir Hekmati, speaks to journalists in Vienna, Austria, on June 29, 2015. Amir Hekmati, a U.S. Marine of Iranian origin who has been imprisoned in Iran since 2011, is expected to be freed Saturday.

It was the Iranians who first proposed a prisoner swap.

The U.S. had complained to Iran about the imprisoned men for years, but the nuclear negotiations finally gave diplomats from the two countries a chance to talk about the problem "face-to-face," the first senior administration official said Saturday.

In the beginning, "Iran asked for a lot of people," Kerry told reporters. Diplomats whittled the list down to exclude anyone who was charged with a crime related to violence or terrorism. All of the Iranians who were released were convicted or accused of violating sanctions related to Iran's nuclear program -- which were lifted on Saturday.

“This should not be viewed as a precedent that would encourage this kind of behavior in the future, and second, as I said, any Iranian citizen who was engaged in any violent crime or support for terrorist activity would not be considered,” a third senior official said Saturday.

Iranian officials have publicly floated the idea of a prisoner exchange, but neither country disclosed the full extent of the negotiations. An Iranian foreign ministry spokesman said in August that 19 Iranian nationals were being held in the U.S. on charges of sanctions violations, but another Iranian official denied that Iran was considering a prisoner exchange. President Hassan Rouhani hinted at a prisoner exchange the following month when he was in New York for the United Nations General Assembly, reasoning that Iranian sanctions violators should be released since sanctions were due to be lifted as part of the nuclear deal.

When the final nuclear accord was announced on July 14, there was no mention of the American prisoners returning home as part of the deal. Even though the Obama administration deliberately avoided tying the prisoners to the nuclear deal, critics of the budding rapprochement between the U.S. and Iran cited the continued imprisonment of the Americans as a key failure of the nuclear negotiations.

To Chase Foster, a former State Department official who worked on Iran matters, it was a sign that the Iranians were negotiating in bad faith and taking advantage of American naiveté. “We have to learn to take a stand and argue from a point of strength,” he told HuffPost in November, arguing that the administration should have insisted the American prisoners return home before agreeing to lift sanctions. “But at this point we have nothing to stand on because we’ve been so shallow, spineless, naive, gullible and stupid.” Foster left the State Department last year.

U.S. officials’ logic for separating the release of the American prisoners from the nuclear deal is threefold: Tacking on additional topics to an already contentious agreement could have lessened the chances of striking a deal, officials reasoned. If the fate of the American prisoners was tied to a nuclear deal, and that effort failed, it could be even more difficult to bring them home at a later point. And finally, giving concessions on the nuclear agreement in exchange for prisoners would legitimize the practice of taking prisoners, only encouraging Iran to arrest more Americans in the future.

But to outside critics, who weren’t privy to the secret prisoner negotiations, the Obama administration had simply abandoned its own citizens who were trapped in Iran.

Just a week before the prisoner agreement was announced, Republican presidential hopeful Jeb Bush said he found it “appalling” that “there’s been no effort to try to support the Americans held hostage by the Iranian government.”

Behind the scenes, there was a concerted effort to free the Americans, and it ramped up after the July 14 nuclear deal was finalized. “The feeling was, we got this really big thing done, we have better diplomatic openings -- now we can really focus on the prisoners,” the second administration official told HuffPost.

"There’s no question that the pace and progress of the humanitarian talks accelerated in light of the relationships forged and the diplomatic channels unlocked over the course of the nuclear talks," Kerry said Saturday.

Kerry raised the issue of the American prisoners during the last conversation he had with Zarif before the nuclear deal was announced in July. Zarif seemed receptive, Kerry said. By November, Kerry thought they had reached an agreement to secure the prisoners' release. But it collapsed in Tehran, and the two countries had to resume negotiations.

Over the past several months, U.S. officials worked to iron out differences with the Iranians and internal divisions within the U.S. government. Department of Justice officials, who were approaching the situation with a rule-of-law attitude rather than as diplomats working through a delicate compromise, balked at the idea of a prisoner swap.

“The Justice Department has had a problem with this the whole time,” said Foster, who was looped in on earlier conversations about the prisoner exchange. “Whoever Iran wants are legitimate criminals … they’re not just people we grabbed off the street so we could have a bargaining chip.”

Iranian diplomats faced similar complications at home: Hard-liners in Iranian security forces oppose any cooperation with the U.S., and resisted releasing the Americans. After the July 14 nuclear agreement, which represented a major victory for Rouhani and his moderate camp, Supreme Leader Ayatollah Ali Khamenei banned further negotiations with the Americans. He did, however, allow Iran to join the Syria peace talks, which the U.S. is part of -- an early indication that his ban could be posturing.

On the same day the historic nuclear deal was announced in July, the prisoner exchange negotiations faced another complication: Iranian security forces stopped Namazi, the American who is still imprisoned in Iran, at the Tehran airport and seized his passport. They arrested him in October.

“They’re not showing fear, that’s for sure,” Foster said of the most recent arrest of an American in Iran. “This sends a strong message -- this is not a regime interested in any form of rapprochement.”

Namazi’s October arrest did not collapse the prisoner talks. If anything, the arrest of another American may have added urgency to the negotiations.

During the next several months, the Americans and Iranians narrowed in on a final list of prisoners to be exchanged. In the end, the Justice Department agreed to release seven Iranians: three who were serving time in prison and four who were awaiting trial, including one who was in the process of negotiating a plea bargain.

The semiofficial Fars News Agency reported the names of the seven Iranians, but the U.S. government has not yet confirmed their identities.

There was at least one final hiccup: the sanctions that the U.S. is expected to impose on Iran's ballistic missile program. The Treasury Department originally intended to announce the sanctions on Dec. 30, a Wednesday. But that Tuesday, Dec. 29, Kerry spoke with Zarif, the Iranian foreign minister, to notify him. Zarif warned Kerry that the people who would be affected by the sanctions included some of the same people involved in the prisoner negotiations -- and said that announcing the sanctions before the arrangement was complete could blow up the deal.

Top Obama administration officials decided to delay the sanctions to save the prisoner exchange talks.

The administration paid a political price for that choice. Officials made the decision to delay the sanctions late on Dec. 29. But because of bureaucratic dysfunction, some members of Congress still received a notification on the morning of the Dec. 30 saying the new sanctions would be announced that morning. The White House had to correct that erroneous notification -- several times -- and the next day, on New Year’s Eve, the Wall Street Journal reported the whole saga and revealed that the White House had delayed imposing the new sanctions.

Lawmakers from both parties slammed the administration, saying the delay suggested Obama was backtracking on his pledge to hold Iran accountable for its ballistic missile program, as well as the country's support for terrorist groups and human rights abuses -- all considered separate from the nuclear accord.

Sen. Chris Coons (D-Del.), who voted in favor of the nuclear deal, publicly questioned the administration’s reasoning and pushed the White House to move forward with the ballistic missile sanctions. House Speaker Paul Ryan (R-Wis.), whose party unanimously opposed the nuclear accord, accused the president of “sweeping these transgressions under the rug” and warned that “key members of [Obama’s] own party are also losing faith in [his] ability to confront Iran.”

The president couldn't tell his critics he had delayed the new ballistic missiles sanctions in order to prevent the secret prisoner swap deal from collapsing. Obama and his team had determined that a few more weeks without the new sanctions in place “wouldn’t affect [the Iranian] ballistic missile program,” the second official said. “We calculated that it was worth it.”

﻿Ryan Grim contributed reporting.

This story has been updated to remove Foster’s account of when and under what circumstances he left the State Department. A State Department official said Foster left in March and confirmed the accuracy of the information he provided about the prisoner talks.