Justice Juan Merchan granted a request by the office of Manhattan District Attorney Alvin Bragg, who is prosecuting Trump, the former president and now the Republican candidate to challenge President Joe Biden for the White House.
"His statements were threatening, inflammatory, denigrating," Merchan wrote, referring to some of Trump's previous attacks on witnesses, prosecutors and judges in various legal cases he faces.
"Such inflammatory extrajudicial statements undoubtedly risk impeding the orderly administration of this court," wrote the judge, who presides in the New York State Supreme Court.
Trump faces 34 felony counts of falsifying business records to hide reimbursements to his former lawyer Michael Cohen for a $130,000 payment to porn star Stormy Daniels to buy her silence before the 2016 election about a sexual encounter she claimed to have had with Trump a decade earlier.
Trump denies having an encounter with Daniels, whose real name is Stephanie Clifford.
In a statement, Trump campaign spokesperson Steven Cheung called the gag order unconstitutional.
"American voters have a fundamental right to hear the uncensored voice of the leading candidate for the highest office in the land," Cheung said.
Trump's lawyers previously said a gag order would leave him defenseless against attacks by political opponents over the case.
Tuesday's order blocked Trump from speaking about witnesses concerning their role in the case. It also blocked Trump from commenting on court staff, prosecutors other than Bragg himself, and any of their family members if those comments are meant to interfere with the case.
Merchan ruled on March 7 that jurors were to remain anonymous except to Trump, his lawyers, prosecutors and a handful of others, after prosecutors highlighted Trump's history of publicly deriding trial jurors and grand jurors.
The looming hush money trial is one of four criminal cases Trump is confronting ahead of the Nov. 5 U.S. election. It could be the only one to reach trial before the election. He has pleaded not guilty to all and called them politically motivated.
The gag order was similar to restrictions a federal judge imposed last year in a criminal case over Trump's efforts to overturn his 2020 election loss to Biden.
In a separate, civil fraud case brought by New York Attorney General Letitia James, another state judge fined Trump $15,000 last year for twice violating a gag order against publicly commenting about court staff.
Trump faces state criminal charges in Georgia over efforts to reverse his 2020 loss to Biden in the state, and federal criminal charges in Florida over his handling of sensitive government documents after leaving the White House in 2021.
Trump is appealing a $454.2 million judgment in the civil fraud case for misstating the values of his family real estate company's properties to dupe lenders. On March 25, a mid-level state appeals court paused that judgment as long as Trump posts a smaller $175 million bond within 10 days.