The way federal authorities told it, the 14 people were dangerous drug dealers who brought large quantities of heroin to D.C. streets. They were an older crew, but what they lacked in youthful energy they made up for in sophistication. They sometimes talked in code, referring to the drugs they sold as “hamburgers” or “doughnuts” to evade detection.

And now, it seems, after being caught in an elaborate federal sting, they will all be back on the streets.

Federal prosecutors are working to dismantle the case — which U.S. Attorney Ronald C. Machen Jr. hailed less than a year ago as an example of law enforcement taking “another step toward making our community safer” — because the investigation was tainted by the possible misconduct of an FBI agent.

On Friday, a federal judge threw out the charges against 13 of the 14 defendants, at prosecutors’ request, and he is expected to terminate the charges against the last defendant soon.

The case is an especially egregious example of the extensive damage that could result from the agent’s alleged malfeasance, details of which came into full public view last week.

The case was largely thrown out only a day after another federal judge dismissed charges against 10 people serving prison time after being convicted of distributing large amounts of heroin in five District neighborhoods. Prosecutors have recommended that charges be dismissed for other defendants, in cases that yielded convictions of both middle- and high-level members of drug operations.

“It is gut-wrenching,” Machen said Friday in an interview. But he said he has an obligation to “preserve the integrity of the process.”

The FBI agent, Matthew Lowry, 33, is alleged to have tampered with drug and gun evidence, although no charges have been filed. Two law enforcement officials familiar with the investigation said he took heroin earmarked for trial and used it himself. He was found near the Navy Yard in late September slumped over the wheel of an unmarked FBI vehicle, and investigators found two drug evidence bags, heroin and two firearms inside, officials said. But it is unclear how Lowry’s use of the drugs affected the cases.

“Somebody did something wrong,” said Kevin Whitman, 55, a D.C. resident who had pleaded guilty and was in jail awaiting sentencing in the case that was largely thrown out Friday. “Somebody stole some money, stole some drugs or did something. That’s the only thing it could be.”

Lowry’s attorney, Robert C. Bonsib, declined to comment on specific allegations against Lowry, but he said some of the accusations were “grossly overblown.”

For their part, some of those charged in the same case as Whitman said federal authorities misinterpreted innocuous conversations from a wiretap and treated low-level users as drug kingpins. Whitman said he is a recovering addict but pleaded guilty because recorded phone calls “made it sound like I was doing something that I wasn’t doing.”

George Ball, 65, said he rejected generous plea offers because he could not stomach confessing to a crime he did not commit. He said he was connected to the case only because the organization’s alleged kingpin was a childhood friend whom he kept in touch with.

“I had nothing to do with the organization or anything else,” Ball said. “This has really been an experience for me.”

Federal authorities saw things differently.

In announcing the charges in December, Machen said the investigation “shows our resolve to target organizations that are bringing cocaine, heroin and other dangerous drugs into the District of Columbia.” The investigation was conducted coast to coast — authorities alleged that a California supplier had shipped drugs to the D.C. area — and involved large quantities of cocaine and heroin.

Investigators spent thousands of hours of manpower on the case and managed to tap the phone of the man alleged to lead the crew in the District, Lester Pryor, 63. Police said they listened to 84 calls between Pryor and a drug connection in Los Angeles. Pryor allegedly arranged a shipment a month, mostly to a barbecue restaurant in the H Street NE corridor whose owner hired ex-offenders, veterans and low-income youths.

After one court hearing early in the case, U.S. Magistrate Judge John M. Facciola took note of the unusual age of the defendants but said that did not negate the danger they might pose.

“Most of them are older than the defendants in this court and have family and other community connections,” the judge wrote. “Strangely, they seem to lead two lives. One is a normal life with family and in the community but the second is the daily buying and selling of drugs in that very same community. . . . Indeed, that their drug dealing is disguised under the patina of normalcy makes it all the more insidious and pernicious.”

Now authorities must grapple with the possibility of that activity returning to the streets and their substantial investment of manpower having gone to waste. Machen said in a statement that it was painful to set aside cases “where agents and prosecutors have spent so much time and effort” taking down a drug network.

Authorities began tapping phones in May 2013 and had undercover informants buying drugs. The barbecue restaurant on H Street, Inspire Barbecue, shuttered in June to make way for condominiums, seemed a central hangout, and police said in court documents that they watched as drugs packaged in 12-inch-square cardboard boxes arrived by Priority Mail. One box, authorities said, contained 1.5 kilos, or more than three pounds, of cocaine.

The wiretap caught discussions of shipments of as much as 20 pounds of heroin, according to court documents. Chef Furard Tate, who ran Inspire, said that he has known Pryor through family connections for years but that he did not know anything about drugs being run through the restaurant.

Some defendants had colorful nicknames, Sweet Baby James, for instance. Others kept it simple: E, Mo and Ty. Pryor went by “Les,” but in coded phone conversations, he was the “old dude.” His criminal record includes eight convictions since 1981; the charges include petty larceny, receiving stolen goods, possession of cocaine and theft. He is a lifelong District resident, single, unemployed and has one child.

Police said in court documents that after the drugs arrived at the restaurant, Pryor would distribute them to street dealers in transactions completed at the Brookland Metro station and along Florida Avenue and Rock Creek Church Road NW. Police said they watched as packages were transferred from Pryor’s Toyota Yaris to other vehicles.

Authorities said the group stored money in a safe-deposit box at a Bank of America branch in suburban Maryland. On Oct. 29, 2013, police seized $68,000 from the box and left behind a cryptic note about contacting police. Then the agents listened in as Pryor’s daughter called her father and said: “There’s a note in the box. Everything is gone.”

At first, Pryor didn’t suspect that he was being targeted. “It’s not a total negative because if it were there would be handcuffs involved,” he said on the recorded call. “You understand, they would have come to me immediately. That’s why it’s so baffling and puzzling what’s going on.”

Court records indicate that almost all of the defendants were released in mid-October — including those who had been sentenced — although they were placed under some type of court monitoring. With the criminal charges dismissed, the monitoring — at least in this case — will end.

According to court records, those charged in the case range in age from the 40s to mid-60s, and previous criminal convictions — many of them very old — include drug trafficking and murder. The murder conviction resulted from a shooting in 1980 on Chapin Street NW; the defendant, Brandon Beale, is 59 and described in court papers as disabled.

While serving his murder sentence at the District’s now-closed Lorton prison in Virginia, Beale received a bachelor’s degree in urban studies through a program offered by the University of the District of Columbia. In an interview with The Washington Post in 1992, when he was 37, Beale said, “I don’t think I’ll ever return to this institution, unless it’s in a capacity to help. Education makes that difference.”

Most of the defendants lived in the District, though some became residents of Prince George’s County in Maryland or Stafford County in Virginia.

Ron Earnest, whose client James Burkley, 60, pleaded guilty and was sentenced, said federal authorities clearly devoted significant resources to the investigation. He said he “can only imagine” how the prosecutors and agents who worked the case and followed the rules must feel to see the charges evaporate.

“I’m sure this is very unpleasant for the other side,” he said.

Although law enforcement officials will certainly rue their release, some of the men had jobs and family responsibilities, and several said that they — at worst — were addicts selling drugs to pay for their own habits.

Whitman said he works as a home health aide. Ball — who said he has 10 children, 28 grandchildren, 11 great-grandchildren — does administrative work for a psychiatric association. The others include a barber, a Montgomery County public schools janitor and a hospital hazardous-waste processor.

The case’s ramifications might not end with the defendants’ release. Robert L. Jenkins Jr., whose client Anthony McDuffie pleaded guilty and was awaiting sentencing, said he is hopeful that prosecutors will release more information about Lowry’s alleged wrongdoing so that those incarcerated for months might be able to consider taking other legal action.

“While they’re delighted that they are out — and it doesn’t look like they will ever be required to return on these charges — I don’t think it stops there,” Jenkins said. “It seems as though their approach is: ‘You don’t need to concern yourself with the reasons why. Just be happy with the fact that you’re out.’ I don’t think that’s fair.”

Jennifer Jenkins contributed to this report.