A federal judge on Friday ruled in favor of CNN and reporter Jim Acosta in a dispute with President Trump, ordering the White House to temporarily restore the press credentials that the Trump administration had taken away from Acosta last week.

In a victory for the cable network and for press access generally, Judge Timothy J. Kelly granted CNN’s motion for a temporary restraining order that will prevent the administration from keeping Acosta off the White House’s grounds.

The White House revoked the reporter’s press pass last week after a heated exchange between him and President Trump and a brief altercation with a press aide at a news conference. Acosta, CNN’s chief White House correspondent, is the first reporter with a so-called hard pass to be banned.

CNN sued President Trump and other White House officials on Tuesday over the revocation. Kelly’s ruling was the first legal skirmish in that lawsuit. It has the immediate effect of sending Acosta back to the White House, pending further arguments and a possible trial. The litigation is in its early stages, and a trial could be months in the future.

Hours after the judge’s decision, Acosta resumed his post at the White House.

Kelly, whom Trump appointed to the federal bench last year, handed down his ruling two days after the network and government lawyers argued over whether the president had the power to revoke a reporter’s access. In explaining his decision, Kelly said he agreed with the government’s argument that there was no First Amendment right to come onto the White House grounds. But, he said, once the White House opened up the grounds to reporters, the First Amendment applied.

His ruling, however, primarily emphasized evidence indicating that the White House’s decision to boot Acosta had violated the Fifth Amendment, which guarantees due process in government actions. He said the White House’s decision-making was “so shrouded in mystery that the government could not tell me . . . who made the decision.” The White House’s later written arguments for banning Acosta were belated and weren’t sufficient to satisfy due process, Kelly said.

Slideshow by photo services

“We are gratified with this result and we look forward to a full resolution in the coming days,” CNN said in a statement. “Our sincere thanks to all who have supported not just CNN, but a free, strong and independent American press.”

Acosta added: “I just want to thank all my colleagues in the press who supported me this week. I want to thank the judge [for this ruling]. And let’s go back to work.”

In comments made in the Oval Office afterward, Trump said the White House would write rules to satisfy the court’s due-process concerns. He also suggested his administration would keep up the legal fight with CNN: “We will end up back in court and we will win.”

Said Trump, “We want total freedom of the press...But you have to act with respect when you’re at the White House, and when I see the way some of my people get treated at news conferences, it’s terrible. So we’re setting up a certain standard, which is what the court is requesting...We always have the option of leaving...and the other media and press in the room won’t be happy.”

White House press secretary Sarah Sanders said a statement after the ruling that “the court made clear that there is no absolute First Amendment right to access the White House,” although the judge actually said reporters have such rights once admitted.

Sanders announced Acosta’s “indefinite” suspension last week after the confrontation at the news conference. Trump and Sanders have had several run-ins with Acosta stretching back to before Trump became president.

Acosta watched Friday’s proceedings from the courtroom in Washington, joined by a team of attorneys including Ted Olson, a former solicitor general in George W. Bush’s administration, and Ted Boutrous, a star litigator and media-law specialist.

CNN had argued that the ban on Acosta violated his First Amendment rights because it amounts to “viewpoint discrimination” — that is, the president is punishing him for statements and coverage he didn’t like. The network has also said the action violates Acosta’s Fifth Amendment rights because his exclusion followed no written guidelines or rules and had no appeal or review procedures.

CNN had requested “emergency” relief from the judge, arguing that Acosta’s rights were being violated with each passing hour.

Until the White House’s action last week, no reporter credentialed to cover the president had ever had a press pass revoked.

A government lawyer, James Burnham, argued in a hearing before Kelly on Wednesday that the president was within his rights to ban any reporter from the White House at any time, just as he excludes reporters from interviews in the Oval Office. He said Acosta could report on the president “just as effectively” by watching the president on TV or by calling sources within the White House. He also said CNN wouldn’t be injured by Acosta’s exclusion since CNN has dozens of other journalists credentialed for the White House.

Burnham also explained that Trump’s rationale for Acosta’s ban was his “rudeness” at last week’s news conference, in effect arguing that Acosta’s conduct, not his right to free speech, was the relevant issue.

The assertions drew a rebuttal from CNN’s lawyer, Boutrous, who described the ban on the reporter as arbitrary, capricious and unprecedented. He said White House reporters need access to the premises to meet with sources and to report on untelevised “gaggles,” impromptu discussions with press aides and other officials, so that banning a reporter from the grounds harms his or her ability to do their job.

Media organizations have been alarmed by the White House’s treatment of Acosta, saying that revoking his “hard pass” to enter the White House is a threat to other journalists who might be similarly banned. Trump has suggested other reporters could face a similar fate if they displease him in some unspecified way. Thirteen news organizations, including The Washington Post and Fox News, jointly filed a friend-of-the-court brief supporting CNN’s position. XXXX

The White House Correspondents' Association, which represents journalists in negotiations over access to the president, filed its own brief on Thursday that urged the court “to roundly reject the president’s dangerous legal position.” It disputed the government’s claim that the president has “absolute, unbridled discretion to decide who can report from inside the White House.”

During the presidential campaign in 2015 and 2016, Trump banned more than a dozen news organizations from his rallies and public events, including The Washington Post. But he said he wouldn’t do something similar as president. Last week, he went back on that statement.

Trump’s 2020 reelection campaign has used the CNN lawsuit to drum up contributions, portraying the suit as evidence of “liberal bias” — an assertion Boutrous brought up on Wednesday to demonstrate that Trump had political reasons for banning Acosta.

“CNN is SUING President Trump, Sarah Huckabee Sanders, a Secret Service agent, and other White House officials . . . ” the fundraising email says. “. . . All because they REVOKED Jim Acosta’s press badge after his continuous grandstanding and inappropriate refusal to yield to other reporters.

“President Trump will NOT put up with the media’s liberal bias and utter disrespect for this Administration and the hardworking Americans who stand with us.”