Kevin O’Loughlin was convicted of raping an 11-year-old girl in Framingham in April 1982, a horrific crime he always insisted he didn’t commit.

Three years ago, his conviction was vacated after evidence emerged that he may have been the victim of mistaken identity. On Monday, the 55-year-old was back in court seeking compensation from the state for what he contends was a wrongful conviction that changed the course of his life — including the psychological damage of a four-year stint in state prison and a lifetime trying to escape the shame of the crime.

“I was a convicted child molester,” O’Loughlin told a 12-member jury in Suffolk Superior Court, explaining why prison was particularly terrible for him. On the night of the crime, “I was home with my sister,” he said.

A divorced father of two who lives in Texas, O’Loughlin is seeking compensation under the state’s erroneous conviction law, enacted in 2004 as a means of repaying a “moral debt” to those who can prove their innocence.

O’Loughlin’s case shows how difficult it is to win compensation even after a court has overturned a conviction. Last month, Governor Charlie Baker increased the maximum compensation a plaintiff can win from $500,000 to $1 million, but it is unclear whether the changes are retroactive.

The state attorney general’s office is contesting O’Loughlin’s allegations, saying he needs to prove his innocence to win financial damages. Among expected witnesses will be the victim, now in her 40s, who will testify that she still believes O’Loughlin was her assailant, according to Assistant Attorney General Abigail Fee.

“She did not doubt it then, she hasn’t doubted it since, and she does not doubt it today,’’ Fee said. “He must first meet his burden of proof.”

O’Loughlin’s fight for exoneration was first chronicled by the New England Center for Investigative Reporting in a story published in The Boston Globe two years ago. After evidence that O’Loughlin’s conviction may have been a case of mistaken identity, a Middlesex Superior Court judge vacated his conviction. Prosecutors decided not to refile charges, saying new evidence “casts real doubt on the justice of the conviction,” court records show.

In December, the Framingham Police Department, which was also sued by O’Loughlin, settled for $900,000, according to court records.

Problems with O’Loughlin’s case were first discovered by a Framingham police detective, now retired, who learned that a man who looked like O’Loughlin had been found guilty of several sexual offenses before and after the 1982 rape.

The man, identified in court as Jeffrey Bartley, is currently incarcerated on other charges. Bartley was convicted of rape in 1985, of open and gross lewdness in 1980 and 1981 and of charges related to child pornography in 2012, according to the Sex Offender Registry Board.

On Monday, Kevin Slattery, the retired police detective, told jurors that he knew O’Loughlin growing up, but wasn’t close to him. He grew interested in the case after noticing that Bartley looked “remarkably” like O’Loughlin.

Slattery said he realized that Bartley had also been convicted of a 1994 rape of a 14-year-old girl that had eerie similarities to the 1982 sexual assault. In that case, Bartley had threatened the victim with a knife and used a sock to gag her, he testified.

Slattery explained how he drew a map of places Bartley had been charged for criminal offensesnear the home of the 1982 rape. Jurors also heard an interview Slattery conducted with Bartley, in which the convicted sex offender said he wasn’t sure if he committed the 1982 rape because he would drink to the point of blacking out.

“They are too similar for it to be a coincidence,’’ he said on the taped interview. “It is more than likely that I did” it, he said.

O’Loughlin’s sister Kathy Beevers, also from Texas, testified Monday that she was with her brother at home the night of the crime and had woken him up around 7 p.m. from a nap. Incarceration changed her brother permanently, she said.

“He wasn’t even Kevin,’’ she said. “It’s like you take someone’s soul and rip it out. It was devastating to see.”

Fee questioned whether Beevers’ memory changed over time to support his alibi. In previous testimony, Beevers said she may have woken up her brother earlier, Fee said.

Although O’Loughlin’s compensation claim was not discussed in court, the state also is fighting it on the basis that he already received a settlement from Framingham and under state law can’t recover duplicate damages. Prosecutors also argue that he doesn’t qualify for the raised cap on compensation, saying it is not retroactive.

The changes to the 2004 law came after public defenders, advocates, and former inmates complained it set an unreasonable bar to acquire compensation, forcing many to settle rather than fight a costly legal battle. As of last fall, 67 people had filed for compensation and less than half had received any money, according to state data. The average payout was $364,228.

O’Loughlin is expected to continue his testimony on Tuesday.

This story co-published with the Boston Globe, May 1, 2018.