Two American men sentenced in Iran last month to eight years in prison on spying charges will be freed in two days, Iranian President Mahmoud Ahmadinejad has told a U.S. television network.

Shane Bauer and Josh Fattal were arrested in July 2009 near Iran's border with Iraq, where they say they were hiking in the mountains. A third American, Sarah Shourd, was freed in September 2010 and returned home.

NBC, which interviewed Ahmadinejad in Iran, said in a Twitter message that the Iranian president had told it Bauer and Fattal would be released in two days. The interview was due to air later on Tuesday on NBC's Today show.

Bauer, Fattal and Shourd say they were hiking in the mountains of northern Iraq and, if they crossed the unmarked border into Iran, it was by mistake.

Shourd was freed on $500,000 bail. Bauer and Fattal were convicted at a trial held behind closed doors and share a cell in Tehran's Evin prison.

Their supporters say evidence against them has never been made public, and that the sentence came as a shock after hopes for their release had been boosted by positive comments from Iran's foreign minister.

U.S. President Barack Obama has denied that the Americans, who were working in the Middle East when they decided to hike in the scenic mountains of Iraq, had any link to U.S. intelligence.

The affair has heightened tensions between Tehran and Washington, which severed diplomatic ties after the storming of the U.S. embassy in the wake of the 1979 Islamic Revolution.