US Supreme Court Chief Justice John Roberts has taken the extraordinary step of rebuking President Donald Trump's criticism of a federal judge.
Mr Trump on Tuesday called a jurist who ruled against his asylum policy an "Obama judge".
The president's gibe provoked a stern statement from the head of America's highest court.
Mr Trump has defended his comments, saying Chief Justice Roberts is wrong.
It is the first time the chief justice has spoken against Mr Trump.
"We do not have Obama judges or Trump judges, Bush judges or Clinton judges," Chief Justice Roberts told the Associated Press.
"What we have is an extraordinary group of dedicated judges doing their level best to do equal right to those appearing before them."
Speaking on the eve of America's Thanksgiving holiday, he said an "independent judiciary is something we should all be thankful for".
Mr Trump responded on Twitter on Wednesday, saying the top justice was wrong and that "Obama judges... have a much different point of view than the people who are charged with the safety of our country".
Sorry Chief Justice John Roberts, but you do indeed have “Obama judges,” and they have a much different point of view than the people who are charged with the safety of our country. It would be great if the 9th Circuit was indeed an “independent judiciary,” but if it is why......— Donald J. Trump (@realDonaldTrump) November 21, 2018
He suggested that the 9th Circuit Court, where a federal judge blocked his recent immigration proclamation, opposed his policies on border and safety.
.....are so many opposing view (on Border and Safety) cases filed there, and why are a vast number of those cases overturned. Please study the numbers, they are shocking. We need protection and security - these rulings are making our country unsafe! Very dangerous and unwise!— Donald J. Trump (@realDonaldTrump) November 21, 2018
How rare is this?
It is extremely rare for a senior member of the judiciary to clash with a US president.
Chief Justice Roberts' Supreme Court colleague Ruth Bader Ginsburg has been a far more outspoken critic of Mr Trump.
In 2016, the liberal judge apologised for calling Mr Trump a "faker" in an interview after coming under fire for commenting on a candidate as a jurist.
Mr Trump has previously lambasted federal judges for ruling against his policies. In 2017, he called a federal jurist who reversed his controversial travel ban a "so-called judge" with a "ridiculous" opinion.
Why did Chief Justice Roberts speak out?
Chief Justice Roberts - who was appointed to lead the court in 2005 by President George W Bush - was responding to the news agency's request for reaction to Mr Trump's remark a day earlier.
The Republican president had spoken out following US District Judge Jon Tigar's ruling against a presidential executive order denying illegal migrants the right to seek asylum, calling the 9th Circuit "a disgrace".
"I'm going to put in a major complaint because you cannot win - if you're us - a case in the 9th Circuit and I think it's a disgrace," Mr Trump told reporters outside the White House.
"This was an Obama judge. And I'll tell you what, it's not going to happen like this anymore."
Politicising an impartial judiciary
Analysis by Anthony Zurcher, BBC News
Members of the Supreme Court - in fact, the whole of the federal judiciary- like to think of themselves as above and apart from the tumult of American politics.
For some time, however, such an idea has been honoured more in the breach than the observance, with courts often becoming mired in fiercely partisan matters.
The politicisation of the judiciary is now reaching a crescendo, as Donald Trump repeatedly questions the impartiality and motives of judges.
The president is, with his comments, seemingly chipping away at the authority of a co-equal branch of government.
That may be why the president's latest fusillade against an "Obama judge" prompted a rare and direct rebuke from the head of the judiciary, John Roberts.
The pointed statement seems destined to set off another round of criticism directed at the chief justice, who - after his 2012 ruling upholding the constitutionality of Obamacare - many Trump supporters feel is insufficiently loyal to their cause.
The president was very quick, via Twitter, to call recent lower-court decisions suspending his immigration policies "dangerous and unwise".
That the normally cautious jurist felt compelled to speak out underscores just how fraught the current situation has become.
What is the case Mr Trump was talking about?
This most recent feud with the judiciary relates to the large group of Central American migrants making their way to the US-Mexico border.
Mr Trump had ramped up his rhetoric around the "caravan" of migrants during the mid-term election season, calling the group "an invasion".
He signed a proclamation on 9 November saying that anyone who wants to claim asylum in the US has to come in through official points of entry - and their cases will not be heard if they enter illegally.
A statement at the time said: "We are using the authority granted to us by Congress to bar aliens who violate a presidential suspension of entry or other restriction from asylum eligibility."
What's the current situation at the border?
Mr Trump deployed military troops to help secure the US-Mexico border at the end of last month.
On Wednesday, Defence Secretary Jim Mattis said he had been given authority to use military force to protect border officials if necessary.
Speaking with reporters, Mr Mattis also said that military police armed with batons and shields could be given powers to temporarily detain migrants for "minutes" if, for example, someone was "beating on a border patrolman".
He added that these officers would not carry firearms or have the power to carry out arrests.
About 3,000 members of the caravan have so far arrived in Tijuana, the Mexican city bordering the US, and authorities expect numbers to reach 10,000 in coming weeks.
On Tuesday, the Pentagon released a report to Congress saying the deployment of around 5,900 active-duty troops would cost about $72m (£56m), plus the $138m (£108m) already spent on 2,100 National Guard troops on border missions since April.
In addition, more than $80m (£62m) has been spent to process thousands of migrant children separated from parents under the Trump administration's "zero tolerance" crackdown earlier this year, report US media.
Mr Trump eventually backed down on the policy that saw over 2,000 migrant children taken away from adults at the US-Mexico border between May and June.
Around 140 children remain in government custody as of this week.