It all began in April when federal agents armed with search warrants seized reams of documents and data in a series of raids on Mr. Cohen’s office, apartment and hotel room as part of an investigation into whether he broke the law by — among other acts — paying Ms. Clifford $130,000 not to speak about an affair she claims she had with Mr. Trump. Ever since the raids, Mr. Avenatti has been trying to be formally admitted to the case to protect any records related to Ms. Clifford that were swept up in the searches. But at the same time, Mr. Avenatti has been waging an unyielding publicity campaign against Mr. Cohen, Mr. Trump and other members of the Trump legal camp, appearing on TV — by Mr. Cohen’s lawyers’ count — 147 times in the last 10 weeks alone.

Last week, Mr. Avenatti created a firestorm when he released a report — apparently based on private bank records — that showed that a shell company owned by Mr. Cohen received millions of dollars from a firm with links to a Russian oligarch and from major corporations, including AT&T and the drug maker Novartis. In the following days, Mr. Avenatti accused Mr. Cohen of meeting with a representative from Qatar’s sovereign wealth fund; claimed that Mr. Trump may have bought the silence of two additional (and, for now, unnamed) women; and posted on Twitter a video of Mr. Trump’s lawyer, Rudolph W. Giuliani, in women’s clothing — though only after, it should be said, Mr. Giuliani called Mr. Avenatti a “pimp.”

All of this, Mr. Cohen’s lawyers noted in their memo, was sufficient reason for Judge Kimba M. Wood, who is handling the matter in Federal District Court in Manhattan, to deny Mr. Avenatti’s request for admission to the case. “To our knowledge, this court has never been presented with clearer evidence of the deliberate creation of a carnival atmosphere and inappropriate conduct while an attorney’s application for admission was pending,” the lawyers wrote. “Moreover, this is an unprecedented attack on an individual who has not been charged with any crime.”

As the two sides have traded salvos, a much more sober legal process has been taking place. A special master, Barbara S. Jones, has been sorting through the reams of materials seized from Mr. Cohen to determine which among them are protected by the attorney-client privilege that Mr. Cohen shared with Mr. Trump. Though Mr. Cohen’s lawyers acknowledged that applications like Mr. Avenatti’s are rarely denied, they said that his conduct warranted keeping him out of the case so that Ms. Jones’ “orderly judicial procedures” can proceed without distraction.

Chief among those distractions was the report Mr. Avenatti released, claiming that Mr. Cohen’s company, Essential Consultants, had taken questionable payments from several sources, including a firm with links to the Russian oligarch, Viktor Vekselberg. In their memo filed on Friday, Mr. Cohen’s lawyers said that the report was marred by “inaccurate statements” and that even some of the accurate information it contained came from an unlawful source.