As the charges were dismissed, Mr. Herring, 53, a rangy man dressed in gray slacks and a blue oxford, brought his hands up to his face, his eyes tearing up. If convicted of the top charge of gun possession, he could have faced up to 15 years in prison.

In 2013, Mr. Herring was arrested as he stood next to his bike outside his apartment on a sunny afternoon. He had just gone shopping, and had several plastic bags with him.

The police said Mr. Herring reached into a white plastic bag, removed a gun, put it in a black plastic bag and tossed that bag into the bushes as a plainclothes officer watched him.

Mr. Herring says he lives a quiet, nonviolent life, mostly taking care of his collie, Snowy. His last arrest, for drugs, was in 1997; he says he has been clean since then.

Eight months into the case, prosecutors gave defense lawyers papers showing that the police had requested a $1,000 tip for a confidential informer in this case. The informer had given a highly detailed description, according to the police paperwork, saying “one male black” matching Mr. Herring’s approximate age, height, weight, skin color, hairstyle and outfit, standing where Mr. Herring was standing, “near a bike with several shopping bags,” was carrying a firearm “believed to be a .380 caliber semiautomatic” that was “inside of a shopping bag.”

Police officers arrived about 10 minutes after the call. Mr. Herring “had conveniently not moved an inch, and then like clockwork, chose to display exactly what the supposed C.I. had described at exactly the right time,” Ms. Silberman and another lawyer, Scott Hechinger, wrote in a filing.

The officers involved in Mr. Herring’s case have had their conduct and methods questioned before. One, Lt. Edward Babington, had testified along with other officers in a federal case including a gun charge, prompting District Judge Dora L. Irizarry to call the officers’ testimony “just incredible, and I say ‘incredible’ as a matter of law,” adding that she believed “these officers perjured themselves.” In another federal gun case, prosecutors said they considered Lieutenant Babington to have given inconsistent testimony.