A U.S. federal judge on Friday ordered the Trump administration to immediately reinstate CNN reporter Jim Acosta's credentials to cover the White House, though a lawsuit over the revocation of the pass continues.

U.S. District Court Judge Timothy Kelly, an appointee of President Donald Trump, announced his decision following a hearing in Washington. The judge said Acosta's credentials would be returned immediately and reactivated to allow him access to the White House for media briefings and other events.

The White House said it would comply, but planned to develop "rules" for orderly news conferences.

The White House revoked Acosta's credentials last week after he and Trump tangled during a news conference following the midterm elections. CNN sued and asked the judge to issue a temporary restraining order forcing the White House to give back Acosta's credentials at least temporarily. The judge agreed.

Following the ruling, the network tweeted:

Statement from CNN and <a href="https://twitter.com/Acosta?ref_src=twsrc%5Etfw">@Acosta</a> on today’s ruling: “We are gratified with this result and we look forward to a full resolution in the coming days. Our sincere thanks to all who have supported not just CNN, but a free, strong and independent American press.” —@CNNPR

Trump later told reporters that "people have to behave" and warned of future court action against reporters who do not.

"If they don't listen to the rules and regulations, we'll end up back in court and we'll win," Trump said on Friday. "But more importantly, we'll just leave. And then you won't be very happy, because we do get good ratings."

The suit by CNN alleges that Acosta's First and Fifth Amendment rights were violated by suspending his pass.

While the judge didn't rule on the underlying case, he ordered Acosta's credentials returned for now because he said CNN was likely to prevail on its Fifth Amendment claim — that Acosta hadn't received sufficient notice or explanation before his credentials were revoked or been given sufficient opportunity to respond before they were.

The judge said the government could not say who initially decided to revoke Acosta's hard pass and how that decision was reached.

"In response to the court, we will temporarily reinstate the reporter's hard pass," White House press secretary Sarah Huckabee Sanders said in a statement.

"We will also further develop rules and processes to ensure fair and orderly press conferences in the future."

In a statement following the ruling, Press Secretary Sarah Sanders said the White House would temporarily reinstate Acosta's pass, but added that 'we will also further develop rules and processes to ensure fair and orderly press conferences.' (Jonathan Ernst/Reuters)

'Irreparable harm'

The White House had spelled out its reasons for revoking Acosta's credentials in a tweet from Sanders and in a statement after CNN filed its lawsuit. But the judge said those "belated efforts were hardly sufficient to satisfy due process."

The judge also found that Acosta suffered "irreparable harm," dismissing the government's argument that CNN could simply send other reporters to cover the White House in Acosta's place.

But the judge also emphasized the "very limited nature" of his ruling Friday. He noted he had not determined that the First Amendment was violated.

The judge told lawyers to file additional court papers in the case by Monday.

Fractious history

Trump has made his dislike of CNN clear since before he took office and continuing into his presidency. He has described the network as "fake news" on Twitter and in public comments.

At last week's news conference, which followed the midterm elections, Trump was taking questions from reporters and called on Acosta, who asked about Trump's statements about a caravan of migrants making its way to the U.S.-Mexico border.

After a terse exchange, Trump told Acosta, "That's enough," several times while calling on another reporter.

Watch the combative exchange between Trump and Acosta:

The White House suspended CNN reporter Jim Acosta's press pass after accusing him of "placing his hands on a young woman just trying to do her job as a White House intern" during an exchange with Trump. 0:34

Acosta attempted to ask another question about special counsel Robert Mueller's Russia investigation and initially declined to give up a hand-held microphone to a White House intern. Trump responded to Acosta by saying he wasn't concerned about the investigation, calling it a "hoax," and then criticized Acosta, calling him a "rude, terrible person."

The White House pulled Acosta's credentials hours later.

Shifting statements

The White House's explanations for why it seized Acosta's credentials have shifted over the last week.

Sanders initially explained the decision by accusing Acosta of making improper physical contact with the intern seeking to grab the microphone.

But that rationale disappeared after witnesses backed Acosta's account that he was just trying to keep the microphone, and Sanders distributed a doctored video that made it appear Acosta was more aggressive than he actually was.

On Tuesday, Sanders accused Acosta of being unprofessional by trying to dominate the questioning at the news conference.