A federal judge in Hawaii on Tuesday blocked a third version of President Donald Trump's travel ban.

>> Read more trending news

The ban was scheduled to go into effect at midnight and targeted eight nations, six of which have populations that are majority Muslim.

The state of Hawaii, the Muslim Association of Hawaii and others sought a temporary restraining order to stop the travel ban from going into effect, Politico reported.

U.S. District Judge Derrick Watson, appointed by former President Barack Obama, said the new restrictions ignore a federal appeals court ruling that found Trump’s previous ban exceeds the scope of his authority. The latest version “plainly discriminates based on nationality in the manner that the 9th Circuit has found antithetical to ... the founding principles of this nation,” Watson wrote.

White House press secretary Sarah Sanders called the decision "dangerously flawed" and warned that Watson's order "undercuts the president's efforts to keep the American people safe" in a statement on Tuesday.

In court documents obtained by Politico, Watson wrote that the travel ban "suffers from precisely the same maladies as its predecessor: it lacks sufficient findings that the entry of more than 150 million nationals from six specified countries would be 'detrimental to the interests of the United States.'"

Watson noted that more than six countries are named in the president's most recent executive order -- Chad, Iran, Libya, North Korea, Syria, Venezuela, Yemen and Somalia -- but that his decision was based only on the inclusion of six of the countries.

It's not the first time Watson has slapped down Trump's travel ban. Watson received death threats and had to be given a 24-hour protection detail earlier this year after he blocked the ban in March, Hawaii News Now reported.

Trump signed his first executive order aimed at curbing entry by foreign nationals to the United States just days after taking office in January. The order, which went into effect immediately, caused chaos at airports across the nation as officials attempted to implement the ban.

A court blocked the order nationwide one week later. The government attempted to fight the court order but ultimately withdrew the travel ban. In March the president signed a revised executive order that was subsequently blocked by Watson and a federal judge in Maryland.

The U.S. Supreme Court allowed the administration to partially reinstate a 90-day ban on visitors from Iran, Libya, Somalia, Sudan, Syria and Yemen and a 120-day ban on all refugees. But it said the policy didn’t apply to refugees and travelers with a “bona fide relationship” with a person or entity in the U.S.

The judge’s order Tuesday prevents acting Homeland Security Secretary Elaine Duke and Secretary of State Rex Tillerson from implementing the latest travel ban.

Watson said he would set an expedited hearing to determine whether the temporary restraining order should be extended.

The Associated Press contributed to this report.