But with Mr. Obama and Mrs. Clinton both taking up Ms. Saberi’s cause, analysts said, the political cost of keeping her in prison may have come to seem too high. The fact that the severity of the charges against her was changed, officials said, illustrated the internal tug-of-war over the case.

“They understood that this wouldn’t help them,” said Thomas R. Pickering, a former undersecretary of state who has conducted informal talks with Iranians. “They were asking the U.S. to put words into action, and at the same time, they were going in the opposite direction.”

Image Reza Saberi and his wife, Akiko, waited outside Evin prison in Tehran for their daughter, Roxana Saberi, to be released on Monday. Credit... Hasan Sarbakhshian/Associated Press

Mr. Ahmadinejad is seeking re-election on June 12. The letter he sent to the court was the first time he had intervened in a judicial case in his four years in office. Analysts said it would help his prospects if he could advance negotiations with the United States before the election.

“Mr. Ahmadinejad wants to take serious steps towards improving ties with the United States before the elections,” said Ibrahim Yazdi, a political analyst in Tehran. “If he succeeds, it would be to his interest.”

If the United States were to establish an interest section in Tehran, for example, that would allow Iranians to obtain visas to the United States, without traveling to a third country, as they have to do now.

The United States has made several gestures to Iran. Mr. Obama taped a greeting for the Iranian people on the Persian New Year, and the administration announced that it would take part, along with other major powers, in face-to-face negotiations with Iran over its nuclear program.