HOUSTON/WASHINGTON (Reuters) - When FBI agents arrested Bahram Mechanic in April last year, prosecutors described the Houston-based Iranian-American entrepreneur as an illegal purchasing agent for Iran’s military and a threat to national security.

Bahram Mechanic leaves Federal Detention Center Houston in Houston, Texas January 17, 2016. REUTERS/Daniel Kramer

When the 69-year-old walked out of a Houston detention center on Sunday before dawn, it was with a pardon from President Barack Obama that was negotiated secretly with Iran over months in exchange for the release of four Americans.

The reversal of fortune for Mechanic and six other Iranian men who received clemency in a deal accompanying the lifting of international sanctions on Iran underscores how quickly assumptions about U.S. relations with Tehran have shifted.

The historic swap was marked by uncertainty, concern on both sides over public perceptions and lingering mistrust between Washington and Tehran, according to administration officials and lawyers for six of the Iranians.

The Obama administration required the men to give up the right to profit from any book or movie based on the pardons and give up any legal claims against the United States, the terms of the decrees show.

The Iranians, meanwhile, asked Mechanic - who was among six of the men with dual nationality - to consider taking a trip home as a show of gratitude to the government that had lobbied for his release, according to Mechanic’s lawyer Joel Androphy.

The men’s lawyers say Obama’s actions vindicate an argument they made in court. Mechanic and others, they say, were never a threat; rather, they say, they were immigrant self-starters who were caught up in enforcement of the most sweeping U.S. trade ban.

Obama has credited the sanctions program - and its tight enforcement - for crippling Iran’s economy and forcing it to accept curbs on its nuclear program. A broad U.S. embargo against Iran remains in place, and on Sunday the United States imposed further sanctions targeting Iran’s ballistic missile program.

Lawyers for the Iranians, all but one of whom were imprisoned or facing trial for sanctions-busting, were first presented with details of the clemency offers last week, they said.

Mechanic and Afghahi had been held without bail since their April arrest, while Mechanic’s employee Tooraj Faridi had been out on bail. All three had pleaded not guilty to charges of shipping electronics to Iran and faced up to 20 years in prison if convicted.

“It’s sort of like winning the lottery,” said Kent Schaffer, a lawyer who represents Faridi.

Slideshow ( 4 images )

U.S. Secretary of State John Kerry and aides had been negotiating a prisoner exchange with Iran for over a year. The talks gained momentum in July when the United States and major powers agreed on a deal to lift some sanctions on Iran in exchange for curbs on its ability to develop a nuclear weapon.

In recent weeks, the White House established “a de facto war room” headed by National Security Adviser Susan Rice to coordinate the swap, a senior administration official said.

The aim was to leave no chance that Iran would not free four Americans at the same time that clemency for Mechanic and the other Iranians became effective.

That meant synchronizing minute-to-minute among U.S. officials in Vienna where the nuclear deal was formally implemented on Saturday, Swiss officials in Tehran who were with the Americans and prisons in Texas, Virginia and New York.

“A deal like this creates some trust, but we don’t at this point have a fully trusting relationship,” the administration official said. “Neither side really wanted to be the first one to do anything irreversible.”

NOVEMBER PRISON VISIT

In November, Fariborz Jahansoozan, legal adviser to the Iranian interests section in Washington, visited Mechanic and Afghahi to tell them that they could be on the list for a prisoner exchange, according to Androphy.

Jahansoozan declined to comment.

He visited the men again in early January and suggested a deal was closer, according to Androphy, who said Jahansoozan asked him to keep their conversations confidential.

Then late last week, Justice Department officials told the lawyers for the men that they were in line for a pardon from Obama, they said.

Mechanic, who declined to comment when reached by Reuters, was ready to take the offer. “He wanted out,” Androphy said.

Iran had initially presented a list of dozens of prisoners it wanted released. Though the Iranians were told from the outset Obama would not consider anyone involved in violence or terrorism, “they tried to introduce names that didn’t fit that criteria,” the senior U.S. official said.

WAITING IN HOUSTON

On Friday, Androphy and Mechanic phoned Jahansoozan and the director of the Iranian interests section, Mehdi Atefat, to discuss the Obama pardon offer one last time, Androphy said. Atefat could not be reached for comment.

The Iranian side had a request: Mechanic should go back to Iran, if only for a visit. Mechanic, who has a business in Iran, plans to travel there, Androphy said.

“The Iranians wanted somebody to go back to Iran to make it look like from a political point of view that Iran is not being short changed here,” he said.

U.S. officials told Androphy to be at the federal detention center in Houston before dawn for Mechanic’s release, scheduled for 5:30 a.m. Houston time on Saturday.

That morning Mechanic and Afghahi were ushered into a conference room at the jail wearing the prison uniform of blue jeans and t-shirts. Prison officials allowed Mechanic to embrace his wife, but they were then separated.

The deadline came and went. Prison officials told the group to stand by as they awaited final clearance.

In Tehran, Iranian officials had objected to the wife and mother of Washington Post reporter Jason Rezaian joining him on the same Swiss plane. U.S. officials responded by holding up the release of Mechanic and the other prisoners by almost 24 hours before the Iranians relented, officials said.

On Sunday, at 4:45 a.m. in Houston, as Rezaian and the other Americans prepared to leave Tehran, Mechanic and Afghahi were released.

Mechanic, wearing a blue track suit, and Afghahi, in a tan coat, met a small crowd of family members waiting in the dark. The two men embraced their wives, took some selfies and entered a waiting car, holding the pardons signed by Obama.