The tip to the police was solid: An African-American man, in a striped shirt and a Yankees cap, was carrying a gun in a building in Upper Manhattan. Officers responded and made an arrest.

But where that information came from, and the lengths to which the police and law enforcement agents may have gone to conceal the source, turned a seemingly ordinary gun possession case into a flash point over legal ethics and a sharp dispute between a judge and federal prosecutors.

The judge, Alvin K. Hellerstein of Federal District Court in Manhattan, found that the arresting officers had created a “story to justify” the stop of the man and that federal agents endorsed falsehoods that were “contrived to protect” the identity of a supposedly anonymous source, who was actually a valuable confidential informant.

“A decision was made to coordinate among all the witnesses not to tell the full truth,” the judge said after he heard testimony from the arresting officers and from federal agents who helped to prepare a complaint against the man who was stopped, Tajuan Simmons, or who later testified before a grand jury.