Hikers Shane Bauer, left, and Josh Fattal, right, have been held in Iran for two years.

An Iranian court has sentenced two American hikers held for two years on spy charges to eight years in prison for spying and entering the country illegally, according to a state media report.

Josh Fattal and Shane Bauer, both 29, were arrested in July 2009 while hiking in northern Iraq near the Iranian border. A third hiker, Sarah Shourd, was released on bail in September 2010 and returned to the United States.

The Islamic Republic of Iran News Network's website says Bauer and Fattal have been sentenced to three years each for illegal entry into Iran and five years each for spying for the United States.

It's not clear if that includes time served. They have 20 days to appeal the sentence, according to the report.

The pair pleaded not guilty to espionage charges at their closed-door trial in Tehran earlier this year.

Their lengthy detention has added to tensions between the two countries over issues such as Iran's disputed nuclear program.