“He made it unequivocally clear,” Mr. Zissou said. “His famous statement I’ll never forget was, ‘I’d rather spend the rest of my life in jail than cooperate with them, and spy against anyone else, spy against Americans, spy against Iran. It’s just not my way of doing things.’ ”

Dr. Sheikhzadeh agreed to plead guilty to two charges of tax and sanctions violations, and to pay more than $147,000 in fines and restitution. But prosecutors were not through with him, and suggested while he awaited sentencing that he was more of a threat than they could publicly disclose.

Their strategy ultimately failed, but not before Dr. Sheikhzadeh would undergo what he, his lawyer and his friends depicted as a Kafkaesque ordeal.

Insisting that he was a fugitive risk even though they had seized his American and Iranian passports and his bank account, prosecutors persuaded Judge Pamela K. Chen of Federal District Court to set bail at $3 million.

Further deferring to the prosecutors, the judge ordered Dr. Sheikhzadeh to wear a surveillance anklet, limited his travel to New York City and Long Island, and forbade him from going anywhere near the Iranian mission or contacting its staff.

“I’ve been here for over 40 years, then all of a sudden I commit the crime of the century and decide to go?” he said, recalling his reaction to the bail conditions.

Friends said the investigation took a toll on the normally upbeat Dr. Sheikhzadeh. “I can tell the investigation has been very hard on him,” Louise Jane Graham, a wardrobe stylist and yoga classmate, said in a letter to Judge Chen urging leniency.