A US judge has temporarily restored White House press credentials to CNN correspondent Jim Acosta.

They were revoked following a contentious press conference with US President Donald Trump earlier this month.

The court said there should be a due process in place for limiting a journalist's access to the White House.

US District Judge Timothy Kelly, who is hearing CNN's lawsuit challenging the revocation, ordered the White House to restore Mr Acosta's press pass while the case is pending.

The White House withdrew Mr Acosta's credentials last Wednesday in an escalation of the Republican president's attacks on the news media, which he has called the "enemy of the people".

White House Press Secretary Sarah Huckabee Sanders said in a statement today that Mr Acosta's credentials would be temporarily restored.

"Let's go back to work," Mr Acosta said to reporters after the hearing.

But Mr Trump said 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," Mr Trump said today.

"But more importantly, we'll just leave. And then you won't be very happy, because we do get good ratings."

CNN said in a statement that it "looked forward to a full resolution in the coming days".

In its lawsuit filed on Tuesday in US District Court in Washington, CNN said the White House violated the US first amendment right to free speech as well as the due process clause of the US constitution providing fair treatment through judicial process. The network asked for a temporary restraining order.

Judge Kelly, a Trump appointee, did not address the first amendment's protections for freedom of speech and the press, focusing instead on the due process provision.

"Whatever process occurred within the government is still so shrouded in mystery that the government at oral argument could not tell me who made the initial decision to revoke Mr Acosta's press pass," Judge Kelly said in his verbal ruling.

In court, US government lawyers said there is no first amendment right of access to the White House and that Mr Acosta was penalised for acting rudely at the conference and not for his criticisms of the president.

The judge said White House press secretary Sarah Huckabee Sanders' initial statement that Mr Acosta was penalised for touching a White House staffer attempting to remove his microphone was "likely untrue and at least partly based on evidence that was of questionable accuracy".

The day after the 6 November congressional elections, Mr Trump erupted into anger during the news conference when Mr Acosta questioned him about the Russia probe and a migrant caravan traveling through Mexico.

"That's enough, that's enough," Mr Trump told Mr Acosta, as a White House staffer attempted to take the microphone away from the correspondent. "You are a rude, terrible person."

Ms Sanders had accused Mr Acosta of "placing his hands on a young woman just trying to do her job as a White House intern" and of preventing other reporters from asking questions at the news conference. She called his behaviour "absolutely unacceptable".

Videos of the encounter show Mr Acosta pulling back as the staffer moved to take the microphone at the press conference.

Today, Ms Sanders said the White House "will also further develop rules and processes to ensure fair and orderly press conferences in the future. There must be decorum at the White House".