The two American hikers detained in Iran on charges of spying and illegal entry have been allowed to post $500,000 bail for their freedom.

The bail will allow Shane Bauer and Josh Fattal, who were arrested in the Iran-Iraq border in July 2009, to return home in the U.S., Washington Post and NBC quoted Iranian President Mahmoud Ahmadinejad as saying in an interview. The president, who called the move as a pardon, said the two Americans will be freed in two days.

Last month, Iran's Revolutionary Court sentenced Bauer and Fattal to eight years in prison for alleged espionage. The two were with a female American, Sarah Shourd, when they were arrested.

The three were detained at the Evin prison and charged with espionage. Shourd was freed in September 2010 after posting $500,000 bail and is already back in the U.S.

Bauer and Fattal were convicted of spying at a closed-door trial in August.

Washington maintains that the three American hikers have no link to U.S. intelligence agencies.

U.S. President Barack Obama and other officials have repeatedly called for the release of the two men.