A day after two American hikers received an eight-year jail sentence for allegedly crossing the border illegally into Iran and spying for the United States, it appears the men may now be victims of Iran’s internal political tensions.

Iran has held Shane Bauer and Joshua Fattal in prison for more than two years. In the weeks leading up to their sentencing, senior Iranian officials close to the president made comments to local media outlets that fueled speculation that the two men would likely be released. Iranian President Mahmoud Ahmadinejad had himself urged the court to make a light ruling.

Within the world of Iranian politics, however, a lighter sentence would have created the impression that the judiciary had caved to political pressure from the Ahmadinejad administration.

Thus, the court’s reversal appears to represent more of a message to the president that the court acts independently of his desires and policy objectives than an affirmation of the two men’s guilt, according to analysts inside the Islamic republic.

Coming amid increasing frustration throughout the Iranian government that Mr. Ahmadinejad has overstepped the bounds of his position, the sentencing is also likely designed as a check to the president’s power.

“The judiciary doesn’t want to hand the government any victories or to be dictated to by the government,” says an analyst speaking by phone from Tehran on condition of anonymity.

For the past six years, Ahmadinejad has successfully appointed political allies to senior positions within a number of state institutions and fired those who oppose his policies. Iran’s Supreme Leader Ayatollah Ali Khamenei, who has final say in all government matters, has tacitly approved the Ahmadinejad government's extension of power at the expense of Iran's judiciary and legislature, stepping in only when the president was perceived as having gone too far.

In large part, the president has been engaged in a power struggle to carve out a permanent power base that will endure even after his presidential term ends in 2013. Iran does not have a system of strong political parties and the influence of the president typically ends when his term his over.

As a result, Ahmadinejad has worked to consolidate power in the executive branch – often at the expense of the parliament and judicial branch – and has worked hard to place his political allies in positions of influence.

In May, Ahmadinejad received a rare but significant rebuke from Ayatollah Khamenei, after unilaterally firing intelligence chief Heydar Moslehi without consulting the supreme leader.

In the run-up to Iran's March 2012 parliamentary elections, legislators and conservative political figures have sought to strengthen their political standing as Ahmadinejad continues with his own efforts to shore up his government's influence over key state institutions.

It is amid this climate that Mr. Bauer and Mr. Fattal were tried. Ahmadinejad had encouraged prosecutors to apply a more lenient sentence.

This would have boosted the Iranian president's international standing before his trip to the US in September to speak in New York at the upcoming United Nations General Assembly meeting. An improvement of Ahmadinejad’s image abroad could help him gain more power at home, so the judiciary may have sentenced the American hikers more harshly with the aim of hampering the president’s efforts to consolidate power.

Tehran's chief prosecutor, Abbas Jafari Dolatabadi, said Saturday that the two American men were sentenced to five years imprisonment on charges of spying for the United States and three years for illegally entering Iran, and have 20 days to appeal the verdict, according to the state Islamic Republic of Iran Broadcasting (IRIB) website.

Fattal, Bauer, and a third American, Sarah Shourd, were arrested in July 2009 along Iran's border with Iraqi Kurdistan. Ms. Shourd was released on $500,000 bail last September for health reasons, and is currently back in the US. Her case remains open and she could be tried in absentia.

The disconnect between the Ahmadinejad administration's public expression of hope for clemency and the harshness of the judiciary's verdict is embarrassing for Ahmadinejad's government in light of the president's upcoming travels to New York, according to domestic analysts.

“It was basically to ensure that Ahmadinejad's government doesn't have anything to use for any sort of [Iran-US] rapprochement," said the Tehran-based analyst speaking on condition of anonymity.