Image copyright Getty Images Image caption Jim Acosta was in court to hear the judge's temporary ruling

Donald Trump has threatened to walk out of future press briefings if reporters do not act with "decorum".

The US president was speaking after a Washington DC court ordered the White House to return CNN reporter Jim Acosta's press pass after it was revoked by the US Secret Service.

Mr Acosta's press pass was taken after he clashed with the president during a news conference earlier this month.

Mr Trump played down the ruling, saying it wasn't "a big deal".

But, he said, "people have to behave", adding his staff were "writing up rules and regulations" for the press to abide by, including sticking to the agreed number of questions.

"If they don't listen to the rules and regulations we'll end up back in court and will win," Mr Trump said. "But more importantly, we'll just leave, and then you won't be very happy."

"You can't take three questions and four questions and just stand up and not sit down," he added. "Decorum. You have to practice decorum."

'A great day'

Speaking outside the court earlier in the day, Mr Acosta praised the decision and told reporters "let's go back to work".

The judge said the White House decision likely violated the journalist's right to due process and freedom of speech.

Media playback is unsupported on your device Media caption Donald Trump and CNN's Acosta clash

The ruling forces the White House press office to temporarily return Mr Acosta's "hard pass", the credential that allows reporters easy access to the White House and other presidential events.

Mr Acosta's lawyer called the ruling "a great day for the first amendment and journalism".

How did the row begin?

Mr Acosta was barred from entering the White House a day after he had a heated exchange with President Trump during a news conference on 8 November.

A White House intern tried to take the microphone from Mr Acosta as he attempted to ask the president a second question.

In a statement Mrs Sanders claimed that he had put "his hands on a young woman" during the exchange, during which Mr Trump called the reporter "a rude, terrible person".

CNN sued to have Mr Acosta's pass restored, and their lawsuit was joined by other media groups, including conservative-leaning Fox News.

Image copyright Reuters Image caption Jim Acosta lost his White House access after a fiery exchange with President Trump

Winning the battle but not the war

Anthony Zurcher, BBC News, Washington

With Jim Acosta sitting in the front row of the courtroom, the media won the opening round of what could be an extended legal battle.

Judge Kelly said he was not ruling on the merits of this case, but that the White House did not provide sufficient justification for revoking Acosta's credentials.

That shouldn't come as much of a shock, given that the administration's explanation for the move has shifted multiple times, from a tenuous allegation that the CNN reporter "placed his hands" on a White House intern to a more general assertion that he violated press conference decorum.

What's left to be decided after further hearings and court filings - assuming the case proceeds - is how much power a president has in determining which reporters get to have, and keep, access to the White House.

An administration has discretion to limit the number of passes it gives out, but the balancing of executive power and press rights gets trickier when government officials try to take media credentials away.

What did the judge say?

Judge Timothy Kelly, who was appointed to the bench by Mr Trump last year, said Mr Acosta's constitutional rights outweighed the White House's right to have an orderly news conference, the Washington Post reported.

He also criticised the Trump administration's decision, saying that the process was "so shrouded in mystery that the government could not tell me... who made the decision".

He also called Mrs Sanders' statement claiming that Mr Acosta had inappropriately touched an intern "belated efforts [that] were hardly sufficient to satisfy due process".

But in court documents, the White House argued that the decision was made in order to preserve White House decorum and it did not claim impropriety towards the intern.

Judge Kelly added that the White House was required to restore his White House access, but is under no obligation to call on him during questions.

A hearing on the case is scheduled for next week, but it is unclear if the White House will once again seek to strip Mr Acosta's access, or allow him to resume his work as CNN's chief White House correspondent.

What has the reaction been?

In a statement, CNN said: "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."

Mrs Sanders said the judge "made clear that there is no absolute first amendment right to access the White House" and that her office planned to "temporarily reinstate the reporter's hard pass".

Ben Wizner of the American Civil Liberties Union (ACLU) said that the White House's attempts to silence Mr Acosta had backfired.

"The White House surely hoped that expelling a reporter would deter forceful questioning, but the court's ruling will have the opposite effect.

"The freedom of the press is a bedrock principle, and our democracy is strengthened when journalists challenge our leaders rather than defer to them."