Islamic studies student Mohammad-Amin Valian was arrested on the basis of a photograph taken at a mass demonstration against the rigged presidential election last year.
He was among six people convicted of the Islamic crime of moharebeh, for waging war against God, The Telegraph reports.
Their sentences were announced in an apparent attempt to forestall fresh demonstrations to coincide with Tuesday's annual festival of fire.
Valian's plight -- especially the combination of his young age and the flimsy nature of his offence -- has spurred condemnation of the severity of the sentence.
Meanwhile, clashes were reported on Tuesday night as Iranians celebrated Charshanbe Soori, a pre-Islamic bonfire night.
Leading opposition figures renewed their opposition to President Mahmoud Ahmadinejad in messages to mark the festival.
"Unfortunately, the current republic is plagued with despotism and elections have become meaningless. This government has not been formed upon the people's votes, and the result has been social unrest," Mehdi Karoubi, one of the losing candidates in the election, said
State media had warned people to stay away from the traditional celebrations and said that thousands of extra police and security forces had been deployed to handle troublemakers.
Delhi: Plane-spotters booked under Telegraph Act
Iran a nuclear state now, declares Ahmadinejad
Angelina Jolie had an affair with Mick Jagger?
Security experts ask Eng players to skip IPL
Now, a computer that can read your mind!