Leah Litman is an assistant professor at the University of Michigan Law School. Joshua Matz is a lawyer at Kaplan Hecker & Fink LLP and publisher of the Take Care legal blog.

President Trump’s efforts to add a citizenship question to the 2020 Census ended not with a bang but with a whimper of a news conference tucked after a summit on the state of social media. This startling defeat highlights important limits on the administration’s playbook for laundering bigotry through administrative processes and bald-faced lies. It also showcases how executive abuses of power can be constrained: through congressional oversight and steel-nerved judges committed to the rule of law.

In Department of Commerce v. New York, the Supreme Court invalidated Commerce Secretary Wilbur Ross’s decision to add a question about citizenship to the 2020 census. It held that the reason he had given for adding the question — enforcing the Voting Rights Act — was “a distraction” from the truth. After initially stating it would lay down its arms, and in response to an enraged presidential tweet, the administration hinted Trump might seek to add the question by executive order.

These suggestions recalled how this administration approached the travel ban and the ban on military service by transgender individuals. It first announced an illegal policy motivated by bias and without developing the new rule through any of the usual procedures. Then, after courts enjoined that illegal action, the administration rounded up some lawyers to try to make things look more respectable and present a “new” policy as though history never happened.

This strategy worked for the travel ban. Federal courts halted the original policy on the grounds that it arose from anti-Muslim animus. But after Trump’s lawyers removed the most explicit references to religion and slightly tweaked the list of which countries were subject to the order — in addition to feigning consultation with relevant expert agencies— the Supreme Court upheld a third version of the ban.

Something similar is happening with the ban on military service by transgender individuals. After the administration first announced the ban as a way to put an unexpected presidential tweet into action, numerous courts blocked it as unconstitutional. So the administration put together a group of supposed experts to issue a report and made some cosmetic changes to the policy, and the Supreme Court ultimately allowed the revised policy to go into effect, albeit without reaching a decision on its validity.

But the census case is different. At long last, the administration’s web of lies tangled up not its intended prey but the president’s own priorities. And the separation of powers helped finish off a Trump proposal rather than belatedly allowing it to take effect. The result was a resounding victory for the rule of law over the rule of Trump.

Much credit for that development belongs to U.S. District Judges Jesse M. Furman, George J. Hazel and Richard Seeborg. From the beginning, these capable judges rejected the Justice Department’s procedural high jinks and clumsy efforts to hide the truth. They then wrote powerful opinions that brought into stark relief the simple implausibility of the administration’s asserted rationale for adding a citizenship question. After the Supreme Court agreed that Ross’s rationale was “pretextual,” a legal term for a pure fiction specifically intended to obscure the truth, this trio of judges stood by the integrity of the judicial system. And they did so even as Trump attacked them via tweet, tried to replace his whole legal team in patently deficient motions and engaged in a shockingly open-air search for some passable new pretext for adding a citizenship question.

Perhaps most important, the courts made clear they would not allow the Trump administration to walk away from its repeated representations — at every level of the judiciary — that the census forms could not be modified after June. As a result, had Trump persisted, the doctrine called “estoppel” likely would have prevented his efforts to change the census at this late stage. Courts have tools to deal with parties who opportunistically lie to them, and it seemed clear these federal judges were open to invoking them here.

Of course, courts aren’t the only heroes of this story. Congress played an important role, too. Not this Congress — whose oversight efforts have failed — but prior Congresses that limited presidential authority. Article I of the Constitution entrusts power over the census to Congress, not the executive branch, and Congress assigned responsibility over the census to the commerce secretary, not the president. Unlike the president, the commerce secretary is bound by the Administrative Procedure Act, which requires agencies to issue reasoned and reasonable decisions — and which requires that the reasons they offer in court be genuine, not obvious falsehoods.

Trump has strained virtually every check and balance in our constitutional system. He lashes out at anyone who dares to oppose him and has often persisted — sometimes successfully — when defeated. But here, he took a step too far.

It wasn’t just that Ross lied, and lied ineptly, about his motives. Or that strong evidence emerged that the administration’s real goal was to electorally advantage Republicans and non-Hispanic whites. Or that Trump said he wanted this question for reasons that his own lawyers had unequivocally denied (such as finding “illegals”). The problem was that the decision to add this question was born of lawlessness, persisted in lawlessness and promised more lawlessness if allowed to stand. And in the face of that threat, the courts refused to blind themselves to reality, insisting that truth and reason matter as constraints on the exercise of power.

The administration knows that its rinse-and-repeat strategy might sometimes save unlawful policies. But this time, the administration’s lies worked against them. Courts called falsehoods by their name, statutes constrained executive power, and a national outcry made clear the stakes of accepting Trump’s abuses. That is the most effective recipe for curbing Trump’s abuses of power in the future.

Read more: