Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

In an act of desperation, a homeless man living in Italy pocketed sausage and cheese — worth the equivalent of $4.71 — from a supermarket where he was buying breadsticks.

Ukrainian national Roman Ostriakov was caught, convicted and sentenced to six months in jail last year with a 100-euro ($115) fine.

But in a case drawing parallels to the story of "Les Misérables" protagonist Jean Valjean, Ostriakov has been redeemed: Italy's highest court annulled the verdict against him, according to reports Monday.

Cheese and ham on display at a market in Sardinian Olbia, Italy. Stephan Jansen / AP file

In Victor Hugo's epic French historical novel, Valjean served prison time after stealing bread for his sister's starving children.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

An Italian state prosecutor tried to appeal Ostriakov's sentence in the 2011 case on a technicality, arguing that he should not have been found guilty of theft, but rather attempted theft, because he had been caught before he left the store.

But Italy's Supreme Court of Cassation went further: It threw out the conviction — essentially finding that because the 30-year-old was homeless and hungry, he stole the food from a market in Genoa out of necessity.

"The condition of the accused and the circumstances in which he obtained the merchandise show that he had taken the little amount of food he needed to overcome his immediate and essential requirement for nourishment," it said in a written ruling.

Hugh Jackman as Jean Valjean in the 2012 musical film version of "Les Miserables." In the story, Valjean was sent to jail for stealing bread to feed his hungry family and spent the rest of his life dealing with the consequences. Laurie Sparham / Universal Pictures

The court's lenience was seen as a humanitarian act of mercy by some Italians.

"The court’s decision reminds us all that in a civilized country no one should be allowed to die of hunger," the Italian newspaper La Stampa wrote in a front-page editorial.

Another newspaper, Corriere della Sera, meanwhile, slammed the Italian justice system for taking five years before it decided a case for a theft worth less than $5.