Mayor Marion Barry bitterly complained weeks ago that federal prosecutors were mishandling a probe of District government contracting. At a news conference, he threatened a counterattack in court. Legal papers were drawn up and put on the mayor's desk. But nothing happened.

"It's a matter of strategy and tactics," Barry said a few days later, explaining his inaction. "This is war."

Late Friday, Barry acted. In an unusual suit filed in federal District Court, he complained about "prosecutorial abuse and vindictiveness." The mayor demanded that U.S. Attorney Joseph E. diGenova disclose evidence. Barry asked the court to order a lid on alleged leaks. And he sought unspecified sanctions against diGenova and the news media for allegedly "conspiring . . . to assault the integrity of the grand jury system."

The legal action is dramatic, but city officials and others familiar with previous Barry-diGenova skirmishes have suggested its primary goal is to discourage anyone in authority who may be talking and to show Barry taking the initiative rather than simply reacting.

For the mayor, a court victory of some kind would be nice, too, those familiar with the legal issues said. But they said it probably would be difficult for Barry to prove any wrongdoing by federal authorities because a broad range of public officials and private citizens has access to much of the information involved. While a judge may be assigned to the case as early as today, the suit illustrates the frustration of Barry and his aides. Since May 22, when diGenova announced the end of a 17-month undercover phase of his investigation into alleged corruption in the awarding of government contracts, Barry has sought to run the government amid a stream of probe-related news accounts.

There has been intense internal debate, with disagreement among Barry and his advisers over how he should publicly handle the probe and its sometimes daily revelations. Aides to the mayor said a heated discussion preceded his decision to hold a news conference Thursday in the wake of new reports about his relationship with Karen K. Johnson.

Johnson is one of the prominent figures in the probe and, according to sources, is now cooperating with prosecutors who want to know whether she received payments from contractors in return for her silence in previous investigations.

Barry has denied any wrongdoing. Aides said he was anxious on Thursday night not to have reporters and television cameras trailing him to public events that included a meeting with national Democratic politicians and a dinner with some of the city's business leaders.

In early June, Barry reportedly angered his legal counsel, Herbert O. Reid Sr., by getting outside advice on whether to go to court then. Reid wanted Barry to file suit at once, but others convinced Barry that it would just give the media more to report and embroil him in more legal jousting with diGenova.

The suit gives a glimpse of Barry's concern over the probe and suggests an inconsistency in how he says it has affected the administration.

The mayor has insisted publicly that the probe has had little impact. He has contended that the news media are more interested in it than District residents are. At the same time, Barry has kept appearances on other subjects to demonstrate that he is not preoccupied with the probe.

However, a legal memorandum filed with the lawsuit contended that "illegal and highly unprofessional leaks" about the grand jury investigation "have paralyzed the operations" of city government.

The statement is an example of Barry's leadership style, in which he ties his troubles and his successes to the city as a whole: If the probe interferes with his work, it does the same for the government.

The suit means that since 1984 Barry has tried all three branches of government -- executive, legislative and judicial -- in his so-far unsuccessful attempts to get formal action taken against diGenova and his conduct of investigations.

In August 1984, Reid wrote then-Attorney General William French Smith to ask appointment of a special prosecutor to look into disclosure of grand jury information involving Johnson and a federal probe of alleged drug use by city officials.

Smith took no formal action, but Barry's aides said they believe that the complaint helped stem news media accounts. "The reporting from governmental sources ceased," Barry says in his current court papers.

In August 1986, Reid wrote the Justice Department complaining about alleged leaks about a federal probe of Barry's personal expenses as mayor. Reid also asked the judiciary committees of the House and Senate to probe diGenova's operations.

House Judiciary Chairman Peter W. Rodino suggested that the Justice Department review the complaints. Justice said it believed that leaks came from outside the government and that no action was planned.

Staff writer Nancy Lewis contributed to this report.