BEIRUT, Lebanon  An Iranian prosecutor said Sunday that an American woman held with two friends on espionage charges for more than a year would be freed on $500,000 bail and be allowed to leave the country, Iranian news agencies reported.

The announcement was the latest turnabout in a case that has further strained the poor relations between Tehran and Washington. Contradictory signals from Iran about the fate of the three Americans have also exposed factional infighting in Iran’s government.

Iranian officials first announced Thursday that they would release the woman, Sarah E. Shourd, 32, and said that President Mahmoud Ahmadinejad had personally intervened to free her. But the following day Iran’s judiciary, run by one of the president’s conservative rivals, canceled the release, saying it violated judicial rules.

On Sunday, Abbas Jafari Dowlatabadi, the prosecutor of Tehran’s Revolutionary Court, said at a news conference that Ms. Shourd would be freed once the bail was paid, but that the espionage trial of all three Americans would go forward, Iran’s semiofficial ILNA news agency reported. The other two Americans, Shane M. Bauer and Joshua F. Fattal, both 28, will remain in detention, Mr. Dowlatabadi said.