John Brennan may not know it, but he’s acting in a drama scripted and produced by Donald J. Trump.

As Eli Lake perceptively observed, President Trump isn’t trying to silence Brennan by revoking his security clearance, as the former CIA director’s defenders insist, but elevate him as a foil.

Trump couldn’t hope for a better poster boy for the so-called “deep state” than a former CIA chief who immediately began to sound like a commentator for MSNBC upon leaving government — and, indeed, signed up as a commentator for MSNBC.

It has been the usual practice of former top intelligence professionals to keep their political opinions, and especially their wild-eyed rants, to themselves. They understand that, having been entrusted with some of the most sensitive powers of the US government, they should show forbearance and restraint lest they undermine the reputations of their institutions.

Brennan has had no such compunction. Granted, he’s acted under provocation. Trump has goaded him on Twitter and launched extraordinary broadsides against the work of US intelligence agencies.

Trump often sounds like the guy popping off down at the end of the bar; he’s transformed Brennan, who is supposed to be the consummate career intelligence official, into the guy down at the other end of the bar.

Advantage: Trump. The president always benefits from the fact that his brand depends on violating norms, whereas if his opponents are baited into violating norms in return, they diminish themselves and their cause.

So it is that a former CIA director is combating a president who maintains the top echelons of the intelligence establishment hated him by demonstrating his hatred for him. Once Brennan made the decision to begin letting loose, he inevitably got sucked into the vortex of the #Resistance — that’s where the Twitter followers, the cable hits and the adulation of half the political spectrum are.

This element of our politics rewards the most sweeping and thoughtless condemnations of Trump, which Brennan readily provides, despite recently occupying a post that depended on discrimination and care in expression and thought.

In a notorious tweet, he accused the president of “nothing short of treason” for his craven performance at a joint press conference with Vladimir Putin in Helsinki.

This was the first time on record that a prominent elected official ever committed treason, which usually involves giving away the nation’s secrets or compromising intelligence assets, at a public event extensively covered by the international media.

What did Brennan mean by his charge? He apparently doesn’t know. Pressed by Rachel Maddow of MSNBC, Brennan explained, incoherently, “I said it was nothing short of treasonous. I didn’t mean that he committed treason.”

Oh. Asked point blank if he thinks that the president is serving the Russian government, he said, “I scratch my head a lot,” not the usual standard for alleging that someone committed a capital offense.

Brennan’s conceit is that there aren’t enough people already saying stupid and inflammatory things on Twitter and TV — the nation needs his voice, too.

This has made him the ideal target for Trump, since even some of the former intelligence officials who oppose the revocation of his security clearance are uncomfortable with how he has conducted himself.

The president’s adversaries may consider this unfair, but the institutions Trump targets are best served by not responding in kind. If the president says that the press can’t be trusted because it’s so biased, the press should react by being less biased rather than more.

If he says that he’s being undone by a “deep state” conspiracy, former intelligence officials should be more restrained rather than less.

Brennan either doesn’t understand this dynamic — or doesn’t care. He has threatened a lawsuit and Trump has welcomed one. The president is happy for a war with the most unhinged representative of the intelligence community at hand, and John O. Brennan is playing his role flawlessly.