James Comey's written and oral testimony before the Senate Intelligence Committee demonstrated that the former FBI director is a bona fide American hero.

This doesn't mean that he didn't make a series of errors in handling the investigation of Hillary Clinton. I believe he did. But I also believe people are fallible, and that when they make a misstep, however grave, this does not foreclose the possibility of them doing the right thing in the future.

If Comey's testimony on Thursday gives us an accurate account of the facts, it shows that he did what he was supposed to do as the director of the country's premier federal law enforcement agency, which was to uphold the rule of law, act as a faithful public servant devoted to country over party, and to resist numerous attempts on the part of the president of the United States to co-opt him and manipulate the direction of the criminal investigation that Comey was heading.

That President Trump attempted such co-option and manipulation is blatantly obvious from Comey's testimony. The president implied that Comey owed his job to him. He twice asked for a pledge of personal loyalty. He strongly indicated that he wanted the investigation against Michael Flynn to be dropped. He likewise asked Comey for help in dispelling "the cloud" of the Russia investigation.

Each of those acts or statements was wildly inappropriate. All of them together display a pattern of behavior that can only be described as flagrantly corrupt. Some have suggested it shows that Trump was simply ignorant of proper presidential behavior or perhaps was merely acting like a boss. That is true only if by "boss" we mean "mob boss." It is the behavior of the leader of a criminal syndicate or conspiracy, the actions of someone accustomed to pledges of personal loyalty that supersede and override civic oaths and obligations. This will be true even if no criminal charges are ever brought against the president for these acts and statements.

Confronted with this astonishing display of impropriety on the part of the president, Comey acted with great circumspection — choosing his words and even body language and facial expressions with great care; refusing to pledge personal loyalty to the president or adjust his investigation; making a strenuous effort to avoid private contact and conversations with the president; keeping a detailed record of all such contacts and conversations immediately after they occurred; and sharing an oral account of them with senior colleagues at the FBI.

That's exactly what he needed to do, and exactly what all Americans should hope and expect from a public servant in such circumstances. It's such actions that make the United States a liberal democracy, that keep it from decaying into precisely the kind of kleptocratic and authoritarian regime that Trump (like Vladimir Putin) appears to prefer, and that distressingly large numbers of Republican politicians, media propagandists, and voters seem unimpressed by (at least when they make life difficult for the head of their own party).

To grasp the decisive difference a public spirited individual can make in such a situation, imagine for a moment how the meetings and conversations Comey describes would have unfolded if he hadn’t stood his ground and upheld norms of civic propriety.

When it became apparent to him during a private dinner on January 27 that the president was proposing "some sort of patronage relationship," Comey might have responded affirmatively, with a nod and a smile. When the president allegedly followed up by asserting, "I need loyalty, I expect loyalty," Comey might have replied the way so many members of the Trump administration either explicitly or implicitly do every day — by demonstrating that the president would have his loyalty. "Not to worry, Mr. President," he might have said. "I am here to serve you, personally. Whatever you need, whenever you need it, just let me know."

When on Feb. 14 (the day after national security adviser Michael Flynn resigned) the president dismissed a large Oval Office meeting and indicated that Comey should stay behind to speak privately, the FBI director might have seen this, not as a disturbing development, but as an appealing opportunity to exploit his access to the most powerful man on the planet. And when the president, in private, allegedly raised the criminal investigation of Flynn, saying "I hope you can see clear to letting this go, to letting Flynn go. He's a good guy," Comey might have responded, "Thank you, Mr. President. I would be happy to do that for you."

Within a few days, Comey might have used his powers as FBI director to call off the Flynn investigation, declaring that he had determined there is insufficient evidence to justify continuing with it. Subordinates at the bureau might have objected. But when they did do, Comey might have asked to speak with them individually and in private, making clear behind closed doors that he is the boss at the FBI, and that he needs and expects the personal loyalty of underlings.

When the president called Comey on March 30 to express the hope that he might help to "lift the cloud" of the Russia investigation, Comey might have indicated that he would also be happy to do this, and then acted on the promise by concluding the investigation prematurely.

In this alternative scenario, Michael Flynn would be free from suspicion of criminal activity, Donald Trump's presidential campaign would be cleared of any wrongdoing connected to Russian interference in the 2016 election, and James Comey would almost certainly still be director of the FBI.

Why would it have been wrong for Comey to respond to the president in this way? More broadly, how do public-spirited civil servants know such behavior is wrong when they see or hear about it? Part of it has to do with the guidance provided by the law, and the special counsel along with leaders of Congress are now tasked with determining (among other things) whether the president's words and actions in this matter violated laws against obstruction of justice and abuse of power.

But laws are embedded in something more fundamental that gives ethical orientation to public servants — something that must give ethical orientation to public servants if liberal democracy in America is going to survive this time of trial. This more fundamental thing is a concept of the whole, of the country, of the United States of America, and its good. This concept transcends party and overrides the interests of any single individual — even when that individual occupies the country's most powerful office.

Whatever his faults, James Comey did his civic duty in resisting and documenting President Trump's wholly inappropriate requests. In doing so, he kept the Russian investigation alive and ultimately shed a revealing light on the way the president responded to it at several key moments early on in his presidency. But he also reminded the country, at a tawdry and viciously polarizing time, of what it looks like when a public servant does his civic duty to uphold the rule of law as best as he can in difficult circumstances.

It's for the latter service most of all that he deserves the nation's gratitude.