The Supreme Court gave its approval on Tuesday to the most blatant act of religious discrimination committed by an American president in the modern era, ruling in Trump v. Hawaii that Donald Trump’s travel ban targeting six Muslim-majority countries was a lawful exercise of the executive branch’s immigration powers.

Trump first called for a “total and complete shutdown of Muslims entering the United States” as a candidate in December 2015, later describing it with the euphemism “extreme vetting.” Hostility towards Muslims permeated his presidential bid: He called for surveillance of mosques and frequently told supporters a false story about an American general who dipped bullets in pigs’ blood to stop Islamic terrorism.

In a 5-4 ruling that fell along the court’s conservative-liberal divide, Chief Justice John Roberts wrote that Trump’s extensive record of anti-Muslim animus wasn’t enough to defeat the executive order that gave force to those views. Instead, he anchored the decision in the court’s immigration and national-security precedents, which give extraordinary deference to the judgment of executive branch officials.

“Because there is persuasive evidence that the entry suspension has a legitimate grounding in national security concerns, quite apart from any religious hostility, we must accept that independent justification,” Roberts wrote on behalf of the court. Justices Anthony Kennedy, Clarence Thomas, Samuel Alito, and Neil Gorsuch joined the decision in full.

Tuesday’s ruling is a major victory for the Trump administration, which had lost nearly every legal battle they fought over the ban and its earlier versions in the lower federal courts. The Supreme Court’s decision all but guarantees that the ban will remain in force for the duration of Trump’s presidency. Since it was imposed by executive order, future presidents would be free to repeal it on their own authority. Congress could also theoretically rewrite the nation’s immigration laws to nullify the ban, but would have to overcome Trump’s veto.