Elderly single women in Japan are finding a new way to stave off loneliness — get thrown in prison.

With more than 4 million elderly women living alone in Japan, twice as many as men, the older ladies are increasingly finding accommodations, companionship and medical care behind bars, the Japanese national news agency NHK reported.

At Kasamatsu Prison in Gifu, one fifth of the more than 300 women prisoners are at least 65 years old, prompting prison officials to enlist younger inmates as caregivers, the news outlet said.

“I was alone at home,” said one 76-year-old inmate who is serving her second shoplifting sentence. “It was harsh. I felt miserable and cried.”

The inmate, identified only by the pseudonym Takako Suzuki, raised two children and once sold cosmetics at a department store — but ended up alone and isolated after losing her husband and becoming estranged from her two children.

In prison, she is no longer alone. Suzuki has gotten treatment for dementia and is spared hard labor due to her age and frail health — and is given small manual tasks to pass the time.

Like Suzuki, authorities said many of the aging inmates opt for petty crimes like shoplifting to escape the tedium of living alone on the outside — shoplifting makes up nearly 83 percent of crimes committed by women 70 or older in Japan.

One 85-year-old inmate with no pension and nobody to turn to for help took to shoplifting after her savings ran dry, recently completing an 18-month sentence at Kasamatsu.

The ancient inmate was placed in an aftercare facility in Aichi in Central Japan, where she celebrated her 85th birthday — her first proper birthday celebration in two decades.

Officials have increasingly turned to aftercare programs to cut down on recidivism among the elderly inmates. The 85-year-old ex-con was given a temporary home to transition back to society.

But the trend has put a strain on jailhouse resources, forcing prison officials to train younger, healthier inmates as caregivers for their grayer cellmates.

“We rely on healthy inmates and outside experts,” warden Takao Hosokawa said. “And having our employees work as hard as they can.”

He said one challenge is dealing with so many wheelchair-bound prisoners.