Lima, Peru (CNN) -- An elderly man's brain languishes. His body languishes, too, in prison. No one seems to know he's there.
Before a sudden turn of events this month, this was the story of Juan Navarro, who spent nearly 37 years inside the tough San Pedro prison in the Lima neighborhood of San Juan de Lurigancho.
To be precise, before being released this week, Navarro spent 36 years and eight months in prison. The exactness of this number is important because it is one of the few facts that he has certainty about.
He doesn't know how old he is. He doesn't remember if he ever appeared before a judge. He can't recall if he was convicted.
Dementia and suspected schizophrenia have faded his memory.
The real shock isn't that Navarro, who has given his age as between 76 and 78, can't remember basic facts about his imprisonment. It's that prison and judicial officials don't know, either.
No one in the Peruvian justice system can say whether Navarro was ever convicted. Or sentenced.
They know that he entered the prison system in 1976, as a murder suspect in the province of Arequipa. He was accused of killing his mother. At some point he was transferred to the prison in Lima, but his file remained stored in the province where he was arrested.
His records were destroyed in a prison riot fire there.
Prisons in Peru -- and Latin America, in general -- are known for being overcrowded places where it is not uncommon for inmates to spend weeks, months or even years awaiting a simple hearing.
Inmates -- whatever their guilt or innocence -- are at a disadvantage in such an overburdened system. To get a day in court requires an advocate, if you can afford one, or patience and luck.
The problem is especially severe at the San Pedro prison. Of the approximately 8,600 inmates, only 1,291 have been sentenced, prison director Col. Tomas Garay said.
"It's a problem that we, with our scarce resources, are learning how to manage," he said.
Navarro never had anyone who cared enough to visit him in prison, and any luck went up in smoke when his records burned.
A couple of points of Peruvian law: If you are imprisoned for 36 months without a sentence, you are to be freed. But it's not automatic; someone has to file the paperwork for you. Second, according to laws at the time of his alleged crime, the maximum sentence a judge could give was 35 years.
In other words, even if Navarro had been convicted to the maximum sentence, he should have been released nearly two years ago.
It wasn't until a radio station found and aired a story about his situation this month that anyone stepped forward to help.
A lawyer, Roberto Miranda, announced on television that he would file a writ of habeas corpus on Navarro's behalf, to be followed by a lawsuit.
"The government should recognize and compensate for this very grave judicial error that forced him to remain unjustly incarcerated for a period longer than he should have served," he told RPP Noticias.
But the government beat the lawyer to the punch, and the country's minister of women and vulnerable populations personally intervened and secured the aging Navarro's release.
It was a simple procedure that anyone could have arranged.
"The thing is that this man doesn't have family who could help with the paperwork, so his case remained up in the air," said Cristian Galvan, a psychologist who works at the place where Navarro will live.
Navarro's new home is in a residence that provides shelter for the elderly who have been abandoned.
He doesn't have good memories from the notorious prison.
"They ruined my teeth from so many hits and they chased me with a knife. ... They wanted to slit my throat," he said.
The first thing he did upon being released was to ask to see the ocean.
"Progressively we will begin taking him to different places so he can begin to gain a familiarity because, you understand, these have been 37 years that he has been in a prison where he only saw other inmates," said Julio Rojas, a medic at the home. "For him this is like a rebirth."
CNN's Mariano Castillo reported and wrote the story from Atlanta. Journalist Maria Elena Belaunde reported from Lima.