WASHINGTON -  A US judge in Hawaii on Wednesday issued a nationwide halt to President Donald Trump's temporary travel ban targeting six majority-Muslim countries. It was a stinging rebuke of Trump's second attempt to institute the controversial order just hours before it was to take effect.

Trump responded to the ruling during a public rally on Wednesday night. "This ruling makes us look weak, which by the way we no longer are, believe me," Trump said, vowing to "fight this terrible ruling."

Promising "we're going to win it," Trump said he would take the case to the Supreme Court if need be.

In fact, Trump — who called the current order a "watered down" version of his first attempt — suggested he might want to return to fighting for those stronger travel measures.

US District Judge Derrick Watson wrote in his ruling that the federal government had not proved the ban was needed to protect the US from terrorists trying to infiltrate the country through legal immigration or the refugee programme. He wrote that despite changes made by the White House to the new ban, it clearly violated constitutional protections of religion based on comments made by Trump throughout his presidential campaign.

"A review of the historical background here makes plain why the government wishes to focus on the Executive Order’s text, rather than its context," Watson wrote. "The record before this court is unique. It includes significant and unrebutted evidence of religious animus driving the promulgation of the Executive Order and its related predecessor."

Watson, who was appointed by President Barack Obama in 2013, issued a temporary restraining order, and wrote that it would remain in effect if the Department of Justice appeals the ruling.

Trump called the ruling an "unprecedented judicial overreach" during a rally in Nashville, Tennessee. He hinted that Watson’s ruling was motivated by “political reasons,” and said he would appeal the case all the way to the Supreme Court if necessary.

Trump also quoted from a federal law that gives presidents the power to bar whole classes of immigrants if the president unilaterally deems them “detrimental to the interests of the United States.”

“Whoever is president can say ‘I’m sorry folks, not now, please, we’ve got enough problems’,” Trump said. “We’re talking about the safety of our nation, the safety and security of our people.”

The Department of Justice followed up, saying it "strongly disagrees" with the ruling, calling it "flawed both in reasoning and in scope." In a statement, the department said it would continue defending Trump's order in court. Reaction also poured in from lawyers who opposed the ban.

"Aloha TRO," said Karen Tumlin, legal director for the National Immigration Law Center, referring to the legal shorthand for a temporary restraining order. "This finds, based on constitutional grounds, that indeed the new executive order, just like the first executive order, meant to enact a state policy denigrating Muslims."

Also applauding the court action was New Mexico Attorney General Hector Balderas, who said in a statement that he supported ruling to "halt President Trump's new, illegal travel ban."

“I am pleased that the judge agreed that this new executive order was enacted with a clear, discriminatory intent to act as a poorly-disguised Muslim ban, and that the ban would harm our universities and economy in New Mexico,” Balderas said.

Virginia Attorney General Mark Herring said Trump's travel ban is ‘tainted’. "President Trump tried to trim and tailor his new ban to avoid legal problems, but when something is as tainted as his Muslim ban it's not hard to see it for exactly what it is."

Herring said. "I'm proud to have been part of the fight against this unlawful, unconstitutional, and deeply un-American ban, both in courts here in the Commonwealth and as part of a united effort of state attorneys general."

Trump's second attempt to limit travel from those countries was set to go into effect at 12:01 ET Thursday. A group of states, immigration and refugee advocacy groups, and private residents filed lawsuits to block it, as happened when Trump issued his first travel order in late January. Judges in Hawaii, Maryland and Washington state heard arguments on those legal challenges Wednesday, with Hawaii being the first to issue a ruling.