An intense two-year effort to free two American hikers from prison in Iran involved diplomats, lawyers and leaders from several countries but no direct participation from U.S. officials.

The back story on how Shane Bauer and Joshua Fattal were released Wednesday from Evin prison in Tehran, met by the Swiss ambassador and flown out of Iran on a private plane to the tiny sultanate of Oman highlighted the U.S. government’s limited leverage with the Islamic republic.

A hiking excursion in Iraq’s northern Kurdish region in which three Americans apparently wandered into Iranian territory ordinarily would seem to be a minor incident, easily resolved by low-level diplomacy. But against the backdrop of three decades of mistrust and suspicion between Iran and the United States — and in the absence of diplomatic relations in that period — it generated more than two years of extended negotiations that the Obama administration was forced to follow from the sidelines. The third American, Sarah Shourd, was released on medical grounds last year.

The case stands in sharp contrast to a diplomatic crisis between the United States and Pakistan in January, when CIA contractor Raymond A. Davis fatally shot two men he said were trying to rob him in Lahore. Through negotiations with Pakistani officials, the United States managed to get Davis released from prison in March after relatives of the dead Pakistanis received as much as $2.3 million in “blood money” compensation.

In Iran, the United States had to rely on countries such as Switzerland, Oman and Iraq. Washington was unable to deal directly with Iran’s judiciary or its president, Mahmoud Ahmadinejad.

American hikers Shane Bauer, right, and Josh Fattal, center, sit with Swiss Ambassador Livia Leu Agosti in Tehran's Mehrabad International Airport before leaving Iran for Oman. (HO/REUTERS)

Also stepping into the diplomatic void as advocates for the hikers was a group of Washington-based religious leaders and a former U.S. diplomat, all of whom had previous experience with Iranian clerics and officials.

Iranian lawyer Masoud Shafiei on Wednesday handled the final formalities of a $1 million bail payment sent by Sultan Qaboos bin Said of Oman to the account of the Iranian judiciary.

Another player behind the scenes was Iraqi President Jalal Talabani, who raised the case of the Americans several times in talks with Iranian leaders.

Relations between the United States and Iran were severed in April 1980 as a result of the November 1979 seizure of the U.S. Embassy in Tehran by Iranian militants, who held 52 Americans hostage for more than 14 months. Since then, the two nations communicate through the Swiss Embassy in Tehran, which represents U.S. interests in Iran.

U.S. officials have expressed worries about the lack of communication between Washington and Tehran — not only in matters such as the hikers’ case but regarding incidents in the Persian Gulf, in which a clash of U.S. and Iranian naval ships could lead to war.

In the case of the jailed American hikers, Swiss Ambassador Livia Leu Agosti made a weekly drive to the Iranian Foreign Ministry to seek a resolution. She met the detainees four times in prison and made sure that books, gifts and other packages from their relatives reached them.

“Officially, we act as a surrogate consulate for the U.S.,” she said. “But we also are a confidential diplomatic channel between both countries.”

Agosti found several Iranian officials who assisted in the case, helping to navigate a complex political system that often relies on intermediaries.

Mohammed Javad Larijani, an adviser to Iran’s supreme leader, Ayatollah Ali Khamenei, traveled to New York last year as part of efforts to resolve the hikers’ case. Larijani, an alumnus of the University of California at Berkeley with two high-ranking brothers — one heads the Iranian parliament and the other is chief justice — played a key role in convincing Iranian leaders that it was in their interest to release Bauer and Fattal, even though the two were suspected of espionage and were sentenced last month to eight years in prison.

The wariness was difficult to overcome. In discussions with Agosti, she said, Iranian officials never expressed any doubt that the Americans were up to no good.

“They felt there were plenty of reasons for them to be under suspicion,” Agosti said.