A Suffolk Superior Court judge granted on Tuesday a motion for a new trial on the gun charge facing Sean Ellis, the man whose conviction in the 1993 murder of a Boston police detective was overturned after he spent 22 years behind bars.

The ruling by Superior Court Associate Justice Robert Ullman opens the door for Suffolk County District Attorney Rachel Rollins to file paperwork ending the case — which would exonerate Ellis, who many believe is innocent, once and for all.

In his ruling, Ullman said “justice was not done” because Ellis was not provided with exculpatory evidence that might have changed the outcome of his trial.

“This whole case is a very sad chapter in the history of the criminal justice system,” Ullman said. “Thankfully, this chapter seems to be nearing its conclusion.”

Boston Police Detective John Mulligan was shot to death in his car on Sept. 26, 1993, outside a pharmacy in Roslindale. In the early 1990s, Mulligan and three other detectives — Kenneth Acerra, Walter Robinson and John Brazil — were being investigated for corruption, including the robbery of a drug dealer on Commonwealth Avenue in Boston a few weeks before the murder. Those key details were never revealed to the defense.

Ellis and Terry Patterson, a co-defendant tried separately, were linked to the murder by Acera and Robinson who were being investigated for corruption. Juries in three trials, including two that ended deadlocked, were unaware of the evidence of corruption linked to Mulligan, Robinson, Brazil and Acerra. A jury finally convicted Ellis in 1995, who was 19 at the time.

Ellis’ murder conviction was overturned in 2015. But he remained convicted of the gun charge. Tuesday’s ruling means that Ellis will no longer be a convicted felon, said Jillise McDonough, one of his attorneys.

"He can finally close this chapter and move on,” she said. “This case is no longer open. This is over for him at this point."

Rosemary Scapicchio, another Ellis attorney, said the ruling is a relief to Ellis and his family but that it's impossible for him to get back more than 21 years of his life.

"Sean was locked in a cage," she said. "His freedom was taken from him. He was away from his family. His father passed away while he was in custody. His mother had cancer while he was in custody. And his life was stolen from them for twenty-two years. And now we're able to say it mattered. The Constitution matters. The right to exculpatory evidence matters."

With the final hurdle in the criminal trial over, Ellis' lawyers are expected to file a wrongful conviction lawsuit against the city of Boston.