Mr. Harrell was experiencing what the author Michelle Alexander referred to in her book, “The New Jim Crow,” as “civic death,” said his lawyer, Vanessa Potkin, who works with the Innocence Project in Manhattan. He was unable to reintegrate himself into society. For several years, he drifted in and out of homeless shelters and bounced from job to job: dishwasher, Sheetrocker, journeyman electrician.

“He served four years in prison,” Ms. Potkin said, “but was in essence sentenced to decades of instability.”

While still in prison, Mr. Harrell had written to the Innocence Project asking for help in getting a DNA test that he hoped would clear his name. “The reason I am writing your office,” his original letter read, “is because I am innocent of the crime.” He added that he “cannot begin to explain” the psychological trauma he had endured.

At that point, however, the organization already had thousands of defendants on its waiting list. It was also difficult, Ms. Potkin said, to correspond with Mr. Harrell because of his transient living situation.

Eventually, in 2014, she took the case. She faced an immediate hurdle: Under New Jersey law at the time, only defendants still in prison were entitled to a DNA test. (The law has since been amended.)

But Ms. Potkin persuaded the Monmouth County prosecutor’s office to grant Mr. Harrell an exception. Last month, the test conducted on semen came back in his favor; and on July 22, Christopher J. Gramiccioni, the prosecutor, announced that he would move to have Mr. Harrell’s conviction thrown out, which would trigger the removal of his name from the sex-offender list.

It is hard to know precisely how many cases like Mr. Harrell’s exist across the country. But one man who experienced a similar ordeal is Eddie Lowery, a former Army specialist, who in 1982 was wrongfully convicted of raping a 63-year-old woman as she lay sleeping in her home in Ogden, Kan. Mr. Lowery, who is now 57 and lives in California, served 10 years in prison. When he got out and had to register as a sex offender, he was so afraid of being recognized that he hid his house’s address plate behind a flower pot.