© Tyler Kaufman/The Innocence Project Archie Williams, wearing a cap, was freed from prison on Thursday, after a court determined that he was wrongly convicted of rape and attempted murder in 1982.

All it took was for technicians in a crime lab to run the fingerprints collected at the scene of a rape through a national database. Within hours, the experts had established a match with a serial rapist.

But that was last week — almost four decades after the attack on Dec. 9, 1982, when a woman was raped and stabbed in her home in a well-to-do neighborhood in Baton Rouge, La. A different man, Archie Williams, went to prison for the crime, even though it was known at the trial that the fingerprints were not his.

On Thursday, Mr. Williams was released from the Louisiana State Penitentiary after serving 36 years.

Sign Up For the Morning Briefing Newsletter

The district attorney for East Baton Rouge Parish, Hillar C. Moore III, said in court: “As a representative of the state, I apologize.”

Mr. Williams’s case highlights gaps in the body of legislation that has been passed to protect against wrongful convictions, particularly as DNA science grows more sophisticated. In all 50 states, those who have been convicted can, with a judge’s permission, run DNA evidence through a national database, sometimes yielding a hit on someone else. The same is not true of the national fingerprint database.

Mr. Williams first requested that the fingerprints be run against the national database in 1999, but prosecutors opposed the move and there was no statute entitling him to do so. About four out of five exonerations are achieved without DNA evidence, according to the National Registry of Exonerations. Yet only a handful of states allow post-conviction access to the fingerprint database, much less account for emerging technologies such as facial recognition.

“It was incredibly frustrating to know that there was technology out there that would lead to the truth, that would give him his innocence — and we were blocked from it,” said Vanessa Potkin, a lawyer with the Innocence Project, a nonprofit organization that assisted Mr. Williams with his exoneration.

As the wave of exonerations continues, more attention has been placed on the severe consequences of letting the real perpetrator go free. The man now believed to have committed the Baton Rouge rape that landed Mr. Williams in prison, Stephen Forbes, died in prison in 1996. He had gone on to commit at least five more rapes, according to his own confessions.

There has been no comprehensive accounting of the number of such crimes. But one woman, Jennifer Thompson, who misidentified the perpetrator of a sexual assault against her and wrote a book with the man who was wrongfully convicted, was later approached by another woman who had been assaulted by the real perpetrator.

Ms. Thompson’s husband, Frank Baumgartner, a political scientist, took a close look at North Carolina, finding 36 exonerations dating back to 1943. In nine of them, the real perpetrator was identified, and six of them went on to commit a total of 99 crimes. Thirty-five of the crimes were felonies, and 13 were violent.

In Baton Rouge, Mr. Moore, the district attorney, said the state ran the fingerprints from the 1982 crime scene against a national database in 2009 but did not come up with a match. The Federal Bureau of Investigation has since upgraded to a more powerful system.

“Technology caught up — and came to the benefit of this person,” Mr. Moore said.

A new judge who had been assigned the case, Commissioner Kinasiyumki Kimble, ordered the testing, which was done on March 14 and led to Mr. Williams’s freedom on Thursday.

Mr. Williams said in an interview after his release that the Louisiana State Penitentiary, sometimes referred to as Angola, was a tough place but that he had remained hopeful through his Christian faith.

“There wasn’t a day that passed that I didn’t stay focused on gaining my freedom,” Mr. Williams said. “I always kept a positive mind. I knew one day justice would come.”

Mr. Williams was 22 years old when he was arrested. He is 58 today.

Mr. Williams’s mother moved to a home near the prison so she could visit him more easily. She died in 1999. His father died in 2003.

In March 1995, after Mr. Williams had been in prison for more than a decade, he sent a neatly hand-printed note to Barry Scheck, a founder of the Innocence Project.

“I sit here year after year,” he wrote, “it’s like no one cares.”

Mr. Williams said he believed that no lawyers would help him because he was poor and that the victim’s husband in the case was powerful.

Under Louisiana law, Mr. Williams is entitled to a maximum of $250,000 for his wrongful incarceration, the equivalent of around $7,000 for every year that he was in prison, according to Ms. Potkin.

The case against Mr. Williams rested in large part on the victim’s identification of him.

Jeff Hollingsworth, the prosecutor, acknowledged to jurors in his closing argument that the fingerprints did not match Mr. Williams’s. But he said Mr. Williams’s face was seared in the memory of the victim, who had picked him out in a lineup and identified him as her rapist in court.

“Do you think she didn’t remember that day?” Mr. Hollingsworth said. “Would you forget that face if someone were doing that to you?”

Mr. Hollingsworth said the fingerprints, which were found near the blood stains, could have belonged to someone else, perhaps a plumber or a carpenter, he suggested.

“How many people come through your house?” Mr. Hollingsworth asked the jury. “The air-conditioning man, people who clean your carpets, the little girl home from school.”

Mr. Williams’s lawyer at the trial, Kathleen S. Richey, said the victim had described a different man, a taller one, and had misidentified the placement of a scar. She testified that her assailant had a scar on his clavicle. When Mr. Williams was made to take his shirt off in court, jurors could see that he had a scar on his upper arm, Ms. Richey argued.

But her harshest criticism of the prosecution’s case, which now appears prescient, was the lack of a match for the fingerprints.

“Fingerprints don’t lie,” Ms. Richey told the court.

“It would be a travesty and a danger to convict the wrong man,” she warned the jury in her closing argument.

“The real rapist,” Ms. Richey said, will “laugh at the judicial system and terrorize other innocent women in their homes during the day.”

She appears to have been correct. In 1986, three years after Mr. Williams was convicted, the man now believed to be the rapist, Mr. Forbes, was caught during an attempted rape and burglary of a woman who lived less than two miles from victim in Mr. Williams’s case. Mr. Forbes confessed to having committed four other rapes in 1985 and 1986.

Mr. Williams said he bore no grudge against the victim for wrongly identifying him at the trial 36 years ago.

“God does not let me hold grudges against anyone,” he said, adding that he felt like the biblical Joseph sold by his brothers into slavery in Egypt, where he eventually became a high official in the Egyptian court.

He said his plan now is to “lay back.”

“I want to soak it all in,” he said. “I want to go to college.”