About two hours later, he added that “Stormy will never have to pay” Mr. Trump or his former personal lawyer Michael D. Cohen “a single dime in attorney’s fees, costs or sanctions.” But the tweet containing the second statement was later deleted.

The judge’s order is intended to close out a defamation suit that had alleged that Mr. Trump defamed Ms. Daniels on Twitter last spring. The tweet in question was posted by the president on April 18, one day after Ms. Daniels, whose legal name is Stephanie Clifford, posted a sketch of a man who, she alleged, threatened her in 2011 as she was first considering speaking out about the affair she said she had with Mr. Trump. Mr. Trump called the sketch “a total con job,” depicting “a nonexistent man.”

In an October decision, the court sided with Mr. Trump’s lawyers’ argument that the tweet included an opinion, which the president was free to express, and ordered Ms. Daniels to pay his legal fees.

According to court documents released on Tuesday, Mr. Trump’s team claimed that five lawyers worked on the case, charging anywhere from $307.60 per hour to $841.64 per hour — rates that the court concluded were reasonable.

As recently as last month, the case was a source of tension between Ms. Daniels and Mr. Avenatti, who rose to fame by positioning themselves as critics of Mr. Trump. In a statement provided to The Daily Beast, which was published Nov. 28, Ms. Daniels accused Mr. Avenatti of having filed the defamation suit against Mr. Trump against her wishes. Four days later, Ms. Daniels tweeted that she and Mr. Avenatti had sorted things out.