Ms. Gardner has been at war with much of the St. Louis police force and the local legal establishment since she was elected in 2016, two years after nearby Ferguson, Mo., erupted in protest over a killing by a police officer. The St. Louis police force is mistrusted by many in the African-American community, which makes up half the city’s population.

She took several steps to make the Police Department more accountable, including creating a list of more than 50 officers who could not bring cases for prosecution to her office because of concerns over their credibility. She also indicted the state’s governor at the time, Eric Greitens, who had been a rising star in national Republican politics.

The business manager of the local police union, Jeff Roorda, has called for Ms. Gardner’s indictment, and he recently went on a radio show to suggest that she be removed from office “by force or by choice.”

A special prosecutor, Jerry Carmody, began investigating Ms. Gardner in 2018 after Mr. Greitens’s lawyers accused her of allowing the perjury of a former F.B.I. agent whom she hired to investigate the governor. Ms. Gardner has said that she did nothing wrong, and that she corrected the former agent’s errors as soon as she learned about them. She later dismissed the case against Mr. Greitens.

In an interview, Ms. Gardner said the lawsuit was about making sure she was allowed to implement the platform she was elected on.

“We’re not going to let fear and injustice stop the reforms that are needed,” she said. “This is also about the continuing attacks on progressive prosecutors, not just in St. Louis, but around this country.”