A judge Wednesday dismissed a murder charge and other counts against a Buffalo man after DNA evidence from the scene exonerated him. And DNA evidence led to another man’s being charged.

Erie County Judge Thomas P. Franczyk dismissed the second-degree murder charge against Charles Tubbins, 23, of Kenmore Avenue.

Prosecutors now accuse Ahkeem R. Huffman, 20, of fatally shooting Rashiene T. Carson, of Lockport, in Buffalo’s Riverside area last Nov. 10.

Huffman was arraigned in State Supreme Court on a sealed indictment charging him with second-degree murder, attempted robbery and criminal possession of a weapon.

“The principal duty of a prosecutor is to do justice,” District Attorney Frank A. Sedita III said. “That means it is our duty to not only convict the guilty but also to exonerate the innocent.”

John K. Jordan, Tubbins’ lawyer, said the district attorney deserved credit for seeking dismissal of Tubbins’ charges.

“It doesn’t happen very often,” Jordan said.

But he said prosecutors should not have been so quick to charge Tubbins in the first place. With only eyewitness testimony, the evidence was weak, Jordan said. Prosecutors could have waited for the DNA to be tested before charging Tubbins.

“Charles Tubbins had no prior criminal conviction,” Jordan said. “He had no history of violence, no prior felony, no prior misdemeanor. Before you lock a guy up in the Holding Center, why not wait until the results are back, until you have a little more proof?”

While Tubbins told some innocuous lies to police who initially investigated the shooting, he also cooperated with authorities when he consented to a DNA swab, turned over his cellphone and agreed to have his apartment searched, Jordan said.

The District Attorney’s Office received the DNA results after Tubbins had been indicted on murder and robbery charges in the shooting death of Carson.

Carson was a rear-seat passenger in a car parked in a Getty gas station lot at 595 Ontario St. at 12:50 a.m. when he was shot, police said.

Buffalo police arrested Tubbins about a couple of weeks later after several eyewitnesses identified him from an array of photographs that detectives showed them, according to the District Attorney’s Office.

Jordan said Tubbins was never given a chance to testify before the grand jury that indicted him.

James F. Bargnesi, head of the Homicide Bureau in the Erie County District Attorney’s Office, said surveillance video from the Getty station showed the assailant open the car door and confront Carson before shooting him.

Bargnesi asked the Erie County Central Police Services Forensic Laboratory to test DNA swabbings of the door handle, and the genetic profile did not belong to Tubbins, Sedita said.

After the DNA results came back, the District Attorney’s Office alerted the court and Jordan, and agreed to a $5,000 bail for Tubbins. He was released from custody after posting the bail.

The DNA from the door handle was submitted to the New York State databank and matched Huffman, a convicted felon who resembles Tubbins, Sedita said.

The DNA evidence and incriminating admissions from Huffman were presented to another grand jury and resulted in a new indictment, Sedita said.

Huffman, who was arraigned before State Supreme Court Justice John L. Michalski, remains in custody. He faces 25 years to life in prison if convicted.

Sedita said his office has exonerated 194 people in the past three years, all but three before indictment. All but one were exonerated before a trial.

“In this case, the Erie County District Attorney’s Office, upon being supplied with additional evidence, spearheaded the effort to exonerate the person wrongfully accused and to bring the true assailant to justice,” Sedita said of Tubbins.