A federal judge on Friday ordered the Trump administration to immediately return, on a temporary basis, the press pass of CNN reporter Jim Acosta, who was barred from the White House last week after a contentious encounter with President Donald Trump at a news conference.

Judge Timothy Kelly, who was appointed by Trump a year ago to federal district court in Washington, said the White House must give the credential back temporarily to give Acosta, CNN's chief White House correspondent, a chance to persuade the administration that he should be allowed to keep it.

The White House suspended Acosta's "hard pass," which gives reporters access to the White House complex, shortly after the Nov. 7 news conference. Press secretary Sarah Sanders said she acted because Acosta had refused to surrender the microphone that reporters use to ask questions. Her statement accused him of "placing his hands" on a White House intern who tried to take the microphone back. Acosta's conduct, she said, was "absolutely unacceptable."

Trump addressed the ruling during a bill signing on Friday, saying that the administration was “writing up rules” regarding journalist conduct.

"We have to practice decorum,” Trump said. “We’re setting up a certain standard, which is what the court is requesting.”

Press Secretary Sarah Sanders said Friday’s court order “made clear that there is no absolute First Amendment right to access the White House,” however, that was never the issue in the case. Having allowed reporters in to cover the president, CNN said, the White House could not then pick and choose who get a press pass based on whether a news organization covers the president favorably.

Sanders said the White House would abide by the judge's decision.

“We will temporarily reinstate the reporter’s hard pass," Sanders aid in a statement. "We will also further develop rules and processes to ensure fair and orderly press conferences in the future."

Acosta and Sam Feist, CNN’s Washington bureau chief, entered the White House grounds not long after the ruling, attracting the attention of photographers and video camera operators as they made their way down the driveway.

CNN's @Acosta is back at the White House after a court order restored his press access. He says he is “confident in our system of justice in this country” pic.twitter.com/xR7VXQsAm1 — TicToc by Bloomberg (@tictoc) November 16, 2018

CNN filed a lawsuit Tuesday against Trump, Sanders and other officials, accusing them of violating the First Amendment rights of CNN and Acosta to report on the presidency. "This severe and unprecedented punishment is the culmination of years of hostility by President Trump against CNN and Acosta based on the contents of their reporting," CNN's lawyers said.

Kelly said the White House had denied Acosta's right to due process by suspending his credential with no notice, but the judge did not rule on the First Amendment issues at the heart of the case.

Courts have long held that the government cannot discriminate against disfavored points of view.

Suspending Acosta's press pass, which gives him access to the White House and his office in the building, is "an unabashed attempt to censor the press and exclude reporters from the White House who challenge and dispute the president's point of view," the lawsuit said.

Several other news organizations, including The Associated Press, Fox News, NBC News, The New York Times and The Washington Post, supported CNN. "Reporters covering the White House must remain free to ask questions," they said in a joint statement. "It is imperative that independent journalists have access to the president and his activities and that journalists are not barred for arbitrary reasons."

But the Justice Department told the judge that Acosta's press pass was suspended because he "disrupted the fair and orderly administration of a press conference." The government's legal brief abandoned the claim in Sanders' statement that Acosta had placed his hands on an intern.

As for the First Amendment issue, the government said presidents have the same discretion to regulate access to the White House as they do to select which journalists get interviews or which reporters they call on at news conferences.

The government lawyers said there's no general right for the public or the press to enter the White House, and the First Amendment is not violated when a president exercises discretion to deny access to any of the hundreds of journalists who seek entry to the White House complex. Besides, the Justice Department said, roughly 50 other CNN employees already have White House press passes.

Last week's televised exchange was particularly testy. When Acosta tried to ask a follow-up question, Trump said: "CNN should be ashamed of itself, having you work for them. You are a rude, terrible person."

But the White House response appears to be the first time a reporter's press credential was suspended because of a journalist's demeanor.