A man from Alabama who was sentenced to life without parole after robbing a bakery of $50.75 in his 20s is to be released after more than three decades in prison.

Alvin Kennard, who was convicted of first-degree robbery, was 22 when he was first imprisoned in 1983.

Now, 36 years on, the 58-year-old is finally to be freed after a judge ordered his release from Donaldson correctional facility in Bessemer.

Kennard was given the disproportionately harsh sentence under Alabama’s old Habitual Felony Offender Act, also known as the “three strikes law”. He had previously been sentenced to three years’ probation for three counts of second-degree burglary in relation to one burglary in 1979. The fourth conviction – for the bakery robbery, which was committed with a knife and involved no injuries – meant he was sentenced to life without parole.

Emotional friends and family leapt up and raised their arms in celebration in the court on Wednesday as circuit judge David Carpenter re-sentenced him to time served.

“All of us [were] crying,” his niece, Patricia Jones, told WBRC. “We’ve been talking about it for, I don’t know, 20-plus years, about being free.”

Kennard, who previously worked in carpentry and construction, reportedly told the judge he wants to work as a carpenter. He attended court shackled and wearing a red-and-white striped prison uniform.

“He says he wants to get him a job, he wants to support himself, and we’re going to support him,” said Jones.

Kennard’s attorney, Carla Crowder, who is executive director of Alabama Appleseed Centre for Law and Justice, said following the re-sentencing that Kennard is “overwhelmed”.

“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,” she said “He is overwhelmed at this opportunity, but has remained close with his family, so he has incredible support.”

Crowder, who was appointed to Kennard’s case after it was spotted by a compassionate judge, said there are “hundreds” of prisoners in similar situations still imprisoned because they do not have attorneys. “It’s incredibly unfair and unjust the hundreds of people in Alabama serving life without parole for non-violent, non-homicide crimes,” she added.