Donald Trump came to office knowing that as president of the United States he would have broad discretion in many areas. What he hasn’t learned is that discretion is not the same as unconstrained power, and that the circumstances in which he makes a decision have an enormous impact on its legality and credibility.

His disregard of constraints is evident in two separate episodes that have roiled his early days in office: his attempt to ban Muslim travelers and refugees from the U.S., and his abrupt dismissal of FBI Director James Comey.

Addressing a rally in Florida in February 2017 shortly after the 9th Circuit Court of Appeals halted implementation of the Muslim ban, Trump read out part of the Immigration and Nationality Act. He understood it to give the president “the right to keep people out if he feels it’s not in the best interest of our country.”

He didn’t read the rest of the statute, which prohibits discrimination on the basis of “race, sex, nationality, place of birth, or place of residence.” Courts enjoined the travel ban despite the president’s broad authority over immigration because of his explicit and oft-repeated goal of banning Muslims.

Fast forward to yesterday’s sacking of Comey. There is no law forbidding the president from firing the director of the FBI. But the director is appointed for 10 years, a period that is deliberately meant to span administrations and insulate the position from electoral pressure. The only time an FBI director has been removed was in 1993, when Bill Clinton removed William Sessions for well-documented ethics violations. In other words, the president generally needs a pretty good reason to get rid of the FBI director. And when the FBI director is investigating the president’s election campaign and associates, the reason needs to be better than good. It needs to be a slam dunk.

Trump did try to justify firing Comey: a negative evaluation of the director’s handling of the Clinton email investigation by the deputy attorney general (who studiously avoided recommending dismissal), and the recommendation of the attorney general (who had previously recused himself from investigating the Trump campaign’s Russia ties). But these justifications are obviously pre-textual. The two events cited against Comey are that he breached FBI protocol by announcing that Hillary Clinton would not be indicted and taking the opportunity to nonetheless publicly criticize her handling of confidential documents, and by informing Congress on Oct. 28th that he had reopened the investigation.

Anyone who saw Trump in Michigan exulting over the re-opened Clinton investigation would have a hard time believing that he was offended by the FBI director’s breach of protocol. At the time, Jeff Sessions, then a senator and now the attorney general who “recommended” Trump dismiss Comey, declared that the director had an “absolute duty” to disclose the investigation.

And Comey’s transgressions have been known for months, even as he continued to serve as director of the FBI. The only thing that’s new is that Comey has publicly confirmed that the Bureau is investigating ties between the Trump campaign and Russia. And, according to news reports, grand jury subpoenas for records have recently been issued and the FBI has asked for additional resources for the Russia inquiry. It’s not hard to draw the obvious conclusion from these facts.

The question is, of course, whether Trump will get away with flouting of established norms. He was far from a conventional candidate and won a surprise victory as he broke rule after rule for “how the game is played.” In office, though, it’s been a different story as his signature initiatives, such as the travel ban and the threat to cut funding to sanctuary cities, have been halted by the courts. Although Republicans control both houses of Congress, he hasn’t yet managed to “repeal and replace” Obamacare.

Comey’s firing may or may not be the scandal that brings down Trump’s presidency. But it teaches the lesson that all power has limits—even when they aren’t explicit.