A Philadelphia judge has dropped first-degree murder charges against a man who spent 11 years in prison for a shooting he did not commit.

Dontia Patterson was 17 years old when his friend Antwine Jackson was fatally shot on a city street outside a grocery store in January 2007, court documents show. Mr. Patterson, who lived nearby, called for help and asked people at the scene if they knew what had happened. But he was charged with murder and after two trials, sentenced to life in prison without parole.

On Tuesday, the Philadelphia district attorney, Lawrence S. Krasner, filed a motion that said his office would not try Mr. Patterson a third time, and that evidence had been withheld during his previous trials, one of which had ended with a hung jury. Mr. Krasner requested the charges be dropped, and on Wednesday, Judge Kathryn Streeter Lewis of the Court of Common Pleas agreed.

“I’m just so grateful that finally — after all these years — someone listened to me,” Mr. Patterson said in a statement published by the Pennsylvania Innocence Project, whose investigation of the case helped lead the district attorney’s office to re-examine it. “Since I was 17 I’ve been saying I’m innocent, and every day since my arrest.”