The events appeared timed to boost the image of President Mahmoud Ahmadinejad coinciding with his visit to New York next week for the U.N. General Assembly session. Last year, a third American was released on bail around the same time.
In Washington, Secretary of State Hillary Rodham Clinton said the United States was "encouraged" by Ahmadinejad's comments about freeing Shane Bauer and Elkins Park native Josh Fattal.
"We obviously hope that we will see a positive outcome from what appears to be a decision by the government," Clinton said at the State Department.
The families of Bauer and Fattal said in a statement that they are "overjoyed" by the reports from Iran.
Lawyer Masoud Shafiei said the court would begin the process to free Bauer and Fattal after payment of the bail, which must be arranged through third parties because of U.S. economic sanctions on Iran. The timing of the court's decision is similar to last year's bail deal mediated by the Gulf state of Oman that freed a third American, Sarah Shourd.
"They accepted to set bail to release," Shafiei told The Associated Press after leaving court. "The amount is the same for Sarah."
Ahmadinejad, in an interview aired on NBC's "Today" show, predicted the Americans could be freed "in a couple of days." He described the bail offer as a "humanitarian gesture" and repeated complaints about attention for Iranians held in U.S. prisons.
The Americans were arrested in July 2009 along the border and accused by Iran of espionage. The trio have denied the charges and say they may have mistakenly crossed into Iran when they stepped off a dirt road while hiking near a waterfall in the semiautonomous Kurdish region of northern Iraq.
Last month, Bauer and Fattal, both 29, were sentenced to three years each for illegal entry into Iran and five years each for spying for the United States. They appealed the verdicts. Shourd's case remains open.
Shafiei said he has passed along details of the court's decision to the Swiss Embassy, which represents U.S. interests in Iran because there are no diplomatic relations between Tehran and Washington.
State Department spokeswoman Victoria Nuland said officials were in touch with Swiss envoys "to get more details from the Iranian authorities."
Iran appears to have timed the court decision to coincide with Ahmadinejad's U.N. visit. Last year, Shourd was released on bail just as Ahmadinejad was heading for the annual gathering of world leaders.
But Ahmadinejad was not likely involved closely in any decisions on the case. Iran's judiciary is controlled by the country's ruling clerics, who have been waging relentless pressure on Ahmadinejad and his allies as part of an internal power struggle.
The diplomatic pathways for possible bail payments was not immediately clear. Officials in Oman - which has close ties with the U.S. and Iran - did not immediately respond for comment on whether they could again offer assistance.
The prime minister of Pakistan, which handles Iran's diplomatic interests in the U.S., has been in Iran since Sunday. But there has been no indication that Yousef Raza Gilani is playing any role in the case.
The possible release of the two Americans would remove one point of tension between Iran and the United States, but suspicions still exist on both sides and no thaw is in sight.
Washington and European allies worry Iran is using its civilian nuclear program as cover to develop atomic weapons and have urged for even stronger sanctions to pressure Tehran. Iran denies any efforts to make nuclear weapons.
Iran, meanwhile, is deeply concerned about the U.S. military on its borders in Iraq and Afghanistan, and sharply denounces U.S. influence in the Middle East.
The families of Bauer and Fattal said in their statement that the pair's freedom "means more to us than anything and it's a huge relief to read that they are going to be released."
"While we do not have further details at this time, we are overjoyed by the positive news reports from Iran," the statement said.
"We're grateful to everyone who has supported us and looking forward to our reunion with Shane and Josh," it added. "We hope to say more when they are finally back in our arms."
Shourd is living in Oakland, California; Bauer, a freelance journalist, grew up in Onamia, Minnesota; and Fattal, an environmental activist, is from suburban Philadelphia. Bauer proposed marriage to Shroud while in prison.
The last direct contact family members had with Bauer and Fattal was in May 2010 when their mothers were permitted a short visit in Tehran.
Their case closely parallels that of freelance journalist Roxana Saberi, an Iranian-American who convicted of spying before being released in May 2009. Saberi was sentenced to eight years in prison, but an appeals court reduced that to a two-year suspended sentence and let her return to the U.S.
At the time, a spokesman for the Iranian judiciary said the court ordered the reduction as a gesture of "Islamic mercy" because Saberi had cooperated with authorities and expressed regret.
In May 2009, a French academic, Clotilde Reiss, also was freed after her 10-year sentence on espionage-related charges was commuted.
Last year, Iran freed an Iranian-American businessman, Reza Taghavi, who was held for 29 months for alleged links to a bombing in the southern city of Shiraz, which killed 14 people. Taghavi denied any role in the attack.
Associated Press writers Patrick Walters in Philadelphia, Jeff Baenen in Minneapolis and Matthew Lee in Washington contributed to this report.