Two American hikers, who have been kept prisoner in Iran for two years on suspicion of spying, were set free on Wednesday.

Josh Fattal and Shane Bauer left Iran Wednesday evening local time and flew to Oman, according to Iran's state news agency IRNA.

The men were each released on $500,000 bail -- the same amount paid for the release of Sarah Shourd, the third member of the party. Shourd was released last year.

All three were arrested in July 2009 along the Iran-Iraq border. Fattal and Bauer, both 29, were sentenced last month to eight years in prison.

Their release comes one day before Iranian President Mahmoud Ahmadinejad speaks to the United Nations, said Taufiq Rahim, a Middle East analyst based in Dubai.

Ahmadinejad had hinted recently that the men could be set free.

"I think he's expecting this will give him some political capital ahead of his visit to the United States and his speech tomorrow to the United Nations General Assembly," Rahim told CTV News Channel.

Their release came just moments before U.S. President Barack Obama gave a speech in which he urged UN members to pull together on world issues, whether it be the Arab Spring uprisings, drought in the Horn of Africa or sanctions against Syria.

The Associated Press, which has journalists in Iran, reported that a convoy of vehicles with Swiss and Omani plates were seen leaving leaving the Evin prison in a convoy Wednesday, with Bauer and Fattal inside.

The U.S. has no embassy or diplomatic relations with Iran, and is represented by Switzerland in that country.

Their lawyer, Masoud Shafiei, said he had completed the paperwork for their bail payments and release, and the men were free to leave.

"I have finished the job that I had to do as their lawyer," Shafiei said.

The convoy drove under police escort to Mehrabad airport where they were flown out aboard a plane that was dispatched from Oman last week. When Shourd was released last year, she also left aboard a plane from Oman.

It wasn't clear when the men would be able to return to the U.S. and reunite with their families

The three Americans have all maintained their innocence throughout their ordeal. Bauer, a freelance journalist from Minnesota, Fattal, an environmental activist from Philadelphia, and Shourd, who lives in California, are friends from university.

All three attended the University of California at Berkeley.

In May 2010 Bauer and Fattal were permitted a visit from their mothers. It was the last known contact they have had with family members.

While in prison, Fattal proposed to Shourd.