President Trump’s former press secretary imposed an “unprecedented sanction,” unfairly and probably illegally suspending a White House correspondent's special-access media credential, a federal appeals court in Washington ruled Friday.

The U.S. Court of Appeals for the District of Columbia Circuit unanimously upheld an order restoring journalist Brian Karem’s press pass, finding the reporter did not receive “fair notice” that the press secretary “might punish his purportedly unprofessional conduct.”

Karem, a correspondent for Playboy magazine and CNN contributor, sued former press secretary Stephanie Grisham after his hard pass was pulled for 30 days following a verbal confrontation in the Rose Garden last summer.

“A thirty-day forced hiatus inflicts considerably more than a reputational injury on a journalist, for whom sustained access is essential currency,” wrote Judge David S. Tatel, who was joined by Judges Sri Srinivasan and Cornelia T.L. Pillard.

In its ruling, the court noted that until last year, a press secretary had never even briefly suspended a hard pass based on a journalist’s unprofessional conduct at a White House event, even though the court cited historical examples of reporters “rudely interrupting” presidents and berating press secretaries.

The First Amendment requires the White House to put reporters on notice with clear standards, and government officials cannot deny access for “less than compelling reasons,” the court said.

Karem’s lawyer Theodore Boutrous said in a statement Friday that “particularly today while journalists are facing attacks from all directions across the country, this decision makes clear that the courts will not tolerate these unconstitutional actions.”

The Justice Department declined to comment on the ruling.

Karem’s case began last July after Trump’s remarks following a “summit” of the president’s social media supporters. Grisham said Karem’s behavior was disruptive during an exchange with former White House aide Sebastian Gorka.

Karem was taunted by some in the audience after Trump did not answer his query. Karem responded that members of the audience were “eager for demonic possession.” Gorka then shouted across the audience at Karem, who invited Gorka to “go outside and have a long conversation.”

Even so, the court said Friday, “to the extent Karem’s ‘irreverent, caustic’ attempts at humor (to use the district court’s language) crossed some line in the White House’s view, those transgressions were at least arguably similar to previous journalistic misbehavior” and did not justify a “month’s exile.”

The court dismissed as “absurd” White House concerns that allowing Karem’s behavior would mean the press secretary would be powerless to take action for more egregious conduct.

“The White House can rest assured that principles of due process do not limit its authority to maintain order and decorum at White House events by, for example, ordering the immediate removal of rogue, mooning journalists,” Tatel wrote.

Karem’s lawsuit followed a similar case involving CNN’s Jim Acosta, who is also represented by Boutrous. A judge restored Acosta’s credential after the White House suspended it following a heated exchange with the president at a news conference.

“Today the DC Circuit affirmed what we all know — the work of journalists reporting from the White House is essential to our republic, White House Correspondents’ Association President Jonathan Karl said in a statement. “The WHCA stands ready to fend off efforts by any administration to constrain the rights of journalists or to threaten our ability to do exercise our First Amendment rights.”