Commissioner Davis says officers drawn to this brand of aggressive policing are a special breed: “These are your A-plus cops, the hunter-gatherers of our profession.” They tend to have discretion in how they work and freedom in what they wear, which contributes to a macho ethos and a dress code that, in Baltimore, included backward baseball caps.

“It’s a subculture within a subculture,” Professor Haberfeld said. “They develop this mentality of: ‘We are dealing with the worst of the worst, we are dealing with the scum of the earth, so you don’t tell us how to do our job.’”

Baltimore is not the first city to wrestle with high-profile cases involving plainclothes police officers. In New York in 2014, plainclothes officers were responsible for the death of Eric Garner, whose last words — “I can’t breathe” — became a national rallying cry for police reform. In Palm Beach County, Fla., last year, a plainclothes officer driving an unmarked car was charged with manslaughter and attempted murder after he pulled up alongside a man whose car had broken down and, without identifying himself as an officer, shouted commands and then fired his weapon.

In Miami, an elite street-crime unit was disbanded in 1997 after 11 officers were charged in a federal conspiracy to plant guns on suspects. In Los Angeles, the sheriff’s department decided to fire seven deputies in 2013, after The Los Angeles Times exposed a secretive jump-out squad whose members celebrated shootings and branded themselves with matching tattoos.

But for ambitious officers, the squads have an enduring allure. “They’re given all the toys: the computers, the money, the guns and dress how you feel, do what you want to do,” said Sgt. Louis Hopson, a 36-year veteran of the Baltimore Police Department and the board chairman of a group that represents black officers. “Come to work when you want to come to work, treat people however you want to treat them. It’s very seductive to a young mind.”

Uniformed officers deter crime, but plainclothes officers are better at catching criminals, said John Cornicello, who was a homicide lieutenant in the New York Police Department before he retired in 2012. But, he acknowledged, plainclothes units tend to drift into long lunches and bad habits. When a plainclothes team was responsible for the fatal 1999 shooting of Amadou Diallo, an unarmed man who was reaching for his wallet, Mr. Cornicello said, “the question arose, ‘How well did we prepare them?’”