Image copyright CBS Image caption Alvin Kennard spent most of his adult life behind bars

An Alabama judge has ordered that a man who robbed a bakery of $50.75 be released from his life sentence.

Alvin Kennard, 58, was handed the harsh sentence under strict rules introduced in the 1970s to deter repeat offenders.

The ruling provoked an emotional reaction from friends and family, who have been visiting Kennard throughout his incarceration.

His lawyer, Carla Crowder, said he was "overwhelmed at this opportunity" and would be looked after by family.

He wanted to take up his former job as a carpenter, she added.

In 1983, when he was 22 years old, Kennard robbed a bakery with a knife. Although there were no injuries, he was sentenced to life without parole.

He had previously pleaded guilty to a burglary, meaning he had breached the old Habitual Felony Offender Act, otherwise known as the Three Strikes Law.

The law has now been changed to allow the possibility of parole.

Appearing in his red-striped prison uniform, Kennard told the judge he took full responsibility for his actions.

His family and friends jumped up, cheering and hugging him as the ruling was made.

"All of us cried," said his niece, Patricia Jones. He had been talking about being free for over 20 years, she added.

"What's extraordinary about Mr Kennard is that even when he thought he was going to be in prison for the rest of his life, he really turned his life around," Ms Crowder said, according to The Guardian.

Kennard, who lived in the faith-based wing of Donaldson Correctional Facility in Bessemer, Alabama, told Ms Crowder he had thought about whom he would leave his belongings with, according to ABC News.

She said that due to the levels of deprivation in the prison, "he wanted to make sure that somebody else got his thermals so they could stay warm this winter".