Kenneth Windley was freed Monday after prosecutors and his lawyers won his exoneration in a Brooklyn case accusing him of a robbery in which a man was left with money orders, cash, and a bank book taken during an attack after a trip to a bank and a post office.

Windley, 61, spent nearly two decades in prison for what prosecutors described as a roughly $550 robbery. A judge threw out his conviction and dismissed his case entirely at the request of both prosecutors and Windley’s lawyers, after prosecutors said they now agreed he did not commit the crime.

Windley said outside the Brooklyn courthouse, “It cost me 20 years, but they said they corrected it now. So that’s all that matters. So I’m good with that,” as he left at liberty for the first time since 2007. Prosecutors said new evidence—including confessions from two other men later convicted of similar robberies—supported Windley’s longstanding claim of innocence.

Brooklyn District Attorney Eric Gonzalez said the case was “really a cautionary tale of how things can seem one way but, without careful analysis, not be what it purports to be,” as he shook Windley’s hand outside court. Gonzalez also said, “Had we known what the evidence was, this case should have never happened,” adding that he apologized privately to Windley.

Prosecutors said Windley was arrested in 2005 after buying a stove for his mother with a money order that turned out to be stolen. They said Gerald Ross, 70, was snatched from by two thieves who followed him home from a trip to a bank and a post office, put him in a chokehold, and then took money orders, cash, and a bank book.

Ross regularly got money orders for rent and life insurance payments at that post office, which prosecutors said helped authorities follow a paper trail after the robbery. The trail led investigators to Windley, who had given his name, driver’s license and address when purchasing the stove at an appliance store.

From the start, Windley maintained he had nothing to do with the robbery. Prosecutors said he told investigators he had bought a $542.77 money order at a discount from acquaintances who said it was valid but that the buyer could not use it for a bureaucratic reason.

Windley’s lawyer, David Shanies, told the court Monday, “He was duped.” Prosecutors said Ross identified Windley as one of the thieves from a photo array and later from a live lineup, both at least six weeks after the robbery. Windley testified at his 2007 trial, describing how the acquaintances had approached him and sold him the money order, but the jury convicted him in 2007 of robbery.

Because of prior felony convictions, prosecutors said Windley was sentenced to 20 years to life in prison, and his appeals failed. Prosecutors said Windley told them early on about the men who sold him the money order, including their nicknames and some information about their legal names, and that later a friend and private investigators helped flesh out the men’s identities and persuaded them to come forward.

In sworn statements and interviews with prosecutors’ office representatives, prosecutors said two men told them they robbed Ross together and that Windley was not involved, and the D.A.’s report described the admissions as “compelling.” Prosecutors said the report did not name the two men and referred to them only as “Suspect 1” and “Suspect 2,” and that both were serving prison time on other robbery convictions.

Prosecutors said those other convictions involved male victims in their 60s and older who were followed home from banks and check-cashing offices in Brooklyn in 2005 and 2006, and that if the jury had known the other men’s identities and robbery records, prosecutors concluded the information would likely have raised reasonable doubt about the charge against Windley. No new charges have been brought, prosecutors said, because the legal time frame for bringing charges has run out, and Ross has died.

Windley said Monday afternoon that he was ready to move forward. “I’m just going to move on from there,” he said as he headed to celebrate with his family.