The office’s investigation found that addicts who bought heroin from the witness had prepped the drug over open flames on the townhouse’s first floor, that the floor was lit only by candles and that Ms. Quick had her own connection to the electrical grid, suggesting the fire might well have been an accident.

“These men were wrongfully convicted,” Mr. Hale said.

In a news conference after the hearing, Mr. Thompson said, “This is a case that shouldn’t have been brought, and we have to own up to that.”

After Justice D’Emic granted the motion, the courtroom spectators began clapping, and several stood to applaud.

Afterward, Mr. Vasquez, who had been wiping tears from behind his dark glasses while in court — he developed glaucoma in prison, which a lawyer said was untreated, and he is now blind — used a cane to navigate down the courthouse hallway.

“Those are years that nothing in the world can give me back, no money, no nothing,” Mr. Vasquez said after the proceeding. “It’s just like I lost myself in prison, I lost 33 and a half years of my life. I went in at 30, I come out at 65, so...” Mr. Vasquez shook his head and his sentence trailed off.

Mr. Villalobos, who like Mr. Vasquez has been out on parole since 2012, said he thought “all the time” that he would get his conviction vacated. In 2012, he contacted New York Law School, where Adele Bernhard, a law professor and director of the Post-Conviction Innocence Clinic, and her students worked on the case.