Union officials say they have been fulfilling their mandate to protect their members, airing legitimate concerns about overreach on the part of their civilian overseers. And sympathetic observers have questioned the political motivations of the mayor.

“She seems to suggest that the blame lies elsewhere, when the buck should stop with the mayor, always,” Mr. O’Donnell said. “She’s been there five years. The thing is an institutional disaster. It’s your institution.”

A spokesman for the mayor said that some of her efforts, like disbanding a plainclothes unit linked to an unusual number of excessive-force complaints, began shortly after she took office.

In some cases, the union’s hostility to scrutiny has been self-defeating. In 2014, the Fraternal Order of Police declined to endorse Gregg Bernstein, then the state’s attorney for Baltimore, after members of the union’s endorsement committee complained that Mr. Bernstein had been too aggressive in prosecuting police misconduct, according to two people briefed on the discussions.

Mr. Bernstein, who suffered from diminishing support in districts where the union has long been influential, lost his re-election bid to the current state’s attorney, Marilyn J. Mosby, who has made prosecuting police misconduct a priority. Ms. Mosby recently charged six Baltimore police officers in the death of Mr. Gray, the resident whose death last month set off tumultuous protests around the city.

St. Louis offers a particularly vivid example of the inability of police unions to update their tactics amid widespread frustration with policing. The St. Louis Board of Aldermen first passed a measure creating a civilian oversight board back in 2006. Mayor Francis G. Slay, a Democrat, vetoed the bill at the time, citing its “inflammatory antipolice” language and questioning whether it would survive a legal challenge given that the State of Missouri still formally controlled the local Police Department.

But, in December, after months of outrage following the shooting death of Michael Brown by a police officer in nearby Ferguson, Mr. Slay agreed to support a bill similar to the one he vetoed a decade ago. A spokeswoman for the mayor said that local control of the Police Department now made the bill legally defensible.