VIENNA/WASHINGTON (Reuters) - The day before the Obama administration was due to slap new sanctions on Iran late last month, Iranian Foreign Minister Javad Zarif warned U.S. Secretary of State John Kerry the move could derail a prisoner deal the two sides had been negotiating in secret for months.

Kerry and other top aides to President Barack Obama, who was vacationing in Hawaii, convened a series of conference calls and concluded they could not risk losing the chance to free Americans held by Tehran.

At the last minute, the Obama administration officials decided to delay a package of limited and targeted sanctions intended to penalize Iran for recent test-firings of a ballistic missile capable of delivering a nuclear warhead.

This account of previously unreported internal deliberations was provided by two people with knowledge of the matter.

A third official said Obama had approved the decision to delay the sanctions.

Those unilateral U.S. sanctions are expected to be imposed quickly now after Iran freed five Americans, including Washington Post journalist Jason Rezaian, on Saturday. Eight Iranians accused in the United States of sanctions violations were having charges dropped or sentences commuted on Saturday under the complex prisoner deal, according to court filings and sources familiar with the cases.

The moves came as broader U.S. and international sanctions were set to be lifted after verification that it had met commitments to curb its nuclear program.

But Kerry’s decision not to call Iran’s bluff in December shows how months of clandestine negotiations to free Rezaian and other Americans became deeply intertwined with the final push to implement the nuclear deal, despite the official U.S. line that those efforts were separate.

A U.S. official said on Saturday there was no connection between the nuclear deal and the release of the Americans.

The prisoner swap could also come under scrutiny from critics who have questioned the Obama administration’s resolve in dealing with Iran and ability to follow through on its pledge to keep a hard line on sanctions outside those imposed on its nuclear program.

The episode was one of several diplomatic and military near misses between Iran and the United States in recent weeks, including a quickly defused crisis when 10 U.S. sailors were detained after entering Iranian waters.

TENSE CALLS AND BUREAUCRATIC ERRORS

Details of the prisoner talks were a closely held secret, so even within the Obama administration few people realized how perilously close the swap came to falling through.

U.S. Secretary of State John Kerry steps from his plane upon his arrival in Vienna, Austria on what is expected to be "implementation day," the day the International Atomic Energy Agency (IAEA) verified that Iran has met all conditions under the nuclear deal, January 16, 2016. REUTERS/Kevin Lamarque

On Dec. 29, Kerry told Zarif the United States intended to impose new sanctions on Iran over the missile test firings, which were deemed to have violated a United Nations ban, according to a U.S. official and congressional sources.

Zarif countered that if Washington went ahead, the prisoner swap was off, the sources said.

Kerry spoke by phone that night with Treasury Secretary Jack Lew and a White House official and the decision was made to hold off on any sanctions announcement, they said.

Zarif’s ability to fend off new U.S. sanctions, even temporarily, may have bought him some breathing space with Iranian hardliners who oppose the terms of nuclear deal. They have insisted that any new sanctions would be a show of bad faith by Washington.

But a bureaucratic misstep almost undid Kerry and Lew’s decision. Word of their last-minute intervention to delay the sanctions never filtered down to working-level officials at the State Department during the holiday lull.

Unaware of the change of plan, the State officials went ahead and quietly informed key congressional offices the next morning about the new Iran sanctions targeting about a dozen companies and individuals. They included copies of a news release that the Treasury Department intended to issue.

Officials then abruptly pulled back, telling congressional staffers the announcement had been “delayed for a few hours,” according to an email seen by Reuters. The next day the State Department emailed that sanctions were delayed because of “evolving diplomatic work that is consistent with our national security interests.”

Administration officials then told some congressional staffers confidentially that something big involving Iran was in the works, in an apparent attempt to tamp down criticism from Capitol Hill, a congressional source said.

Leading lawmakers, including some of Obama’s fellow Democrats, chided the White House for delaying the sanctions package and suggested it could embolden Iran to further threaten its neighbors and destabilize the Middle East.

SMALL CIRCLE OF TRUST

The nuclear deal signed on July 14 between Iran and world powers had been widely hailed as a major boost for Obama’s legacy. But he also faced criticism for refusing to make the accord contingent on Iran’s release of Americans known to be held by Iran. The prisoners, accused of spying and other charges, included Rezaian and several other Iranian-Americans.

At a White House news conference the day after the nuclear accord was signed, Obama bristled at a reporter’s suggestion that while basking in the glow of the foreign policy achievement he was all but ignoring the plight of Americans still detained in Iran.

“You should know better,” he said, adding that U.S. diplomats were “working diligently to try to get them out.” But Obama insisted that linking their fate directly to the nuclear negotiations would have encouraged the Iranians to seek additional concessions.

Once the deal was done, Kerry told his staff to redouble efforts to secure the Americans’ release, a U.S. official said. By that time, Brett McGurk, a State Department official, had already been conducting secret negotiations for months with an unnamed Iranian representative, the official said.

In a sign that Iran was looking for a way forward, officials of the Iranian interests section in Washington - Tehran’s de facto embassy – began meetings in August with some of the 12 Iranians held in the United States for violating sanctions. The aim was to see whether they would be willing to return to Iran if a swap could be arranged, according to a person familiar with the cases.

In recent months, senior Iranian officials repeatedly floated the idea of a prisoner exchange, despite apparent opposition from Iranian hardliners.

Kerry informed only a handful of senior lawmakers on a confidential basis on Thursday night that a release of Americans held in Iran was imminent, a congressional source said.

Obama has had some success in keeping such proceedings under wraps in the past. His aides negotiated a deal in late 2014 that led to Cuba’s release of former U.S. aid contractor Alan Gross and a U.S. intelligence operative while Washington freed three Cuban spies.

But it was a prisoner swap earlier that year – the Taliban’s release of alleged U.S. army deserter Bowe Bergdahl in exchange for five Taliban commanders held at Guantanamo Bay, Cuba – that caused a backlash from Republican lawmakers. They argued that Obama failed to give Congress the legally required notice for transfer of Guantanamo prisoners and questioned whether Bergdahl endangered fellow soldiers by slipping away from his post in Afghanistan, provoking a massive manhunt.

On Saturday, Kerry and Zarif joined with European Union foreign affairs chief Federica Mogherini in Vienna for planned “Implementation Day,” which would end a decade of nuclear sanctions on Iran and unlock billions of dollars of its frozen assets.

With the U.S. prisoners free, Obama may now feel freer to go ahead with the missile sanctions, which are far more limited than the nuclear sanctions program that crippled Iran’s economy. U.S. officials have said that the new financial penalties remain on the table and are likely to be revisited soon.