Hidden behind a wall of secrecy is the truth about what really happened during the FBI and CIA’s joint investigation of the Trump campaign and Russia in 2016.

Was it, as former President Barack Obama’s top cop and spy insist, an honest national security probe? Or was it, as Republicans suspect, a domestic political intelligence operation to “dirty up” then-candidate Donald Trump?

Attorney General William Barr doesn’t buy the Team Obama story and is investigating the investigation. Special counsel Robert Mueller’s failure to find evidence of “collusion” bolsters Barr’s hunch.

Trump’s granted Barr the rare unilateral power to declassify sensitive documents held by the CIA and FBI to help him examine events that took place before July 31, 2016, when the FBI claims it opened its probe. Barr will look especially at the CIA’s alleged targeting of the Trump campaign (the agency is prohibited by law from targeting domestic actors).

Barr’s probe of the probe will seek to answer several bedeviling questions.

First, what was CIA chief John Brennan up to in arranging secret interagency task force meetings on alleged collusion in the spring, summer and fall of 2016? He sent classified memos related to these meetings in envelopes to former FBI boss James Comey, Attorney General Loretta Lynch and national security adviser Susan Rice, according to a 2018 House Intelligence Committee report.

Barr will also want to find out how and why Brennan came to apprise Obama of highly classified info provided by a source close to Russian strongman Vladimir Putin — who, according to congressional investigators, was likely a Russian source recycled from a largely debunked dossier compiled by ex-British spook Christopher Steele for the Hillary Clinton campaign.

Plus, did Brennan argue for using the dossier in early drafts of the task force’s much-hyped January 2017 intelligence assessment, which spread the narrative that Putin ordered the alleged Clinton campaign hacking to steal the election for Trump? ­Emails or other communiqués from Brennan are likely to establish that.

More generally, Barr will need to get his hands on case files put together by these agencies as well as the sourcing that informed them, including confidential-source reports summarizing briefings between FBI agents and the informants and assets they jointly handled with the CIA.

Barr should also press for FBI, CIA and State Department records related to Joseph Mifsud, the mysterious Maltese professor whose conversations with Trump campaign aide George Papadopoulos allegedly triggered the original “collusion” probe.

The Obama administration’s inappropriate use of Foreign Intelligence Surveillance Act wiretaps has also been at the heart of this outrage, and Barr will want to uncover how that came about, as well.

Among other things, he should press for details on a 2012 Obama administration request to the FISA court to expand the FBI’s ability to exchange information on surveilled Americans with foreign governments. He might also request redacted portions of a 2017 FISA court opinion scolding Team Obama for “significant non-compliance” with rules protecting the identity of US citizens caught up in foreign intercepts.

Those Obama White House officials who had “unmasked” the names of Trump figures should be held accountable.

Barr will also have to seek an Obama-era “interagency memorandum of understanding” signed by the FBI and CIA enabling outside contractors to gain “improper access,” per the FISA court’s opinion, to raw FISA data from November 2015 to April 2016.

Also sure to be revealing are the still-classified transcripts of some 53 closed-door interviews by the House Intelligence Committee of FBI and Justice Department officials that “demonstrate who was lying and expose the bias that existed against Trump before and after his election,” according to Matt Gaetz (R-Fla.).

Anticipating obstruction and stonewalling, a Barr spokesman said his team of investigators, led by chief investigator John Durham, has directed the FBI, CIA and other intelligence agencies to preserve relevant records and make witnesses available for ­interviews.

It’s plain that Barr and his team have an understanding of where this is all going, and it looks to be going deep. Though the FBI and CIA want the nation to believe Moscow hacked the 2016 election to help Trump win, they may be hiding evidence they themselves meddled in the election to help Clinton win — while ensuring they had checks in place against a renegade Trump presidency — by using FISA warrants to hack into the e-mails of Trump campaign aides and by running a network of spies against them both at home and abroad.

Paul Sperry is an investigative reporter and bestselling author.