The feds have granted immunity to two top execs of the National Enquirer’s publisher so they can spill their guts about the roles President Trump and Michael Cohen played in hush- money payoffs to a porn star and former Playboy Playmate.

In exchange for their cooperation, David Pecker (right), CEO of American Media Inc., and Dylan Howard, the company’s chief content officer, won’t face prosecution for their roles in the payoffs, The Wall Street Journal reported on Thursday.

The Associated Press, meanwhile, reported that the Enquirer kept a safe containing documents on payoffs and other potentially damaging stories it killed as part of its cozy relationship with Trump ahead of the 2016 election.

The Trump records were stored with similar documents involving other celebrities’ “catch-and-kill” deals, in which exclusive rights to people’s potentially explosive claims were bought with no intention of publishing them.

But once the Journal revealed that the tabloid had bought and killed a story about former Playboy model Karen McDougal’s claim of having had an affair with Trump, the documents were removed from the safe in the weeks before Trump’s inauguration, according to the AP.

It was unclear whether they were destroyed or moved to a location known to fewer people.

Pecker, a longtime pal of the president’s, has already met with federal prosecutors and shared details about the payments that Cohen, who was Trump’s personal lawyer, arranged to silence McDougal and porn actress Stormy Daniels.

Both women claim they had affairs with Trump in 2006, shortly after the then-reality-TV star’s wife, Melania, gave birth to their son, Barron.

The president has repeatedly denied hooking up with either woman, and after initially denying knowledge of the payoffs, he now says he learned of them only after they were made.

But in a recording secretly made by Cohen, Trump appears to discuss a possible payment to American Media to buy the rights to McDougal’s affair claim.

Pecker’s help apparently contributed to the case against Cohen made public Tuesday, when the president’s former lawyer pleaded guilty to eight criminal charges, including campaign-finance violations tied to the payments, according to the Journal and Vanity Fair, which first reported Pecker’s immunity deal.

Cohen said he broke federal laws on campaign contributions — at Trump’s direction — by arranging the payments to Daniels and McDougal to bury their claims before the 2016 election.

Daniels was paid $130,000 to clam up. McDougal pocketed $150,000 from American Media for exclusive rights to her claim that she had a roughly yearlong affair with Trump.

But the company never published her story.

Former Enquirer employees who spoke to the AP said negative stories about Trump were dead on arrival dating back more than a decade, when he starred on the NBC reality show “The Apprentice.”

In 2010, at Cohen’s urging, the Enquirer began promoting a potential Trump presidential candidacy, referring readers to a pro-Trump Web site Cohen helped create.

With Cohen’s involvement, the publication began questioning President Barack Obama’s birthplace and American citizenship in print, an effort that Trump promoted for several years, former staffers said.

The Enquirer endorsed Trump for president in 2016, the first time it had ever officially backed a candidate.

Pecker and Trump go way back.

In the late 1990s, as head of Hachette Filipacchi Media, Pecker published Trump Style, a quarterly magazine given to guests at Trump’s properties.

Pecker is also a regular at Trump’s Mar-a-Lago resort in Palm Beach, Fla.

It wasn’t clear whether prosecutors had agreed not to go after American Media for unlawful corporate campaign contributions.

The company — which also publishes Us Weekly, Star magazine and Ok! — is struggling financially and has been restructuring its crushing debt, the Journal previously reported.

Tuesday’s charging documents against Cohen revealed close coordination between American Media and Team Trump.

Prosecutors said that in August 2015, shortly after Trump announced his run for president, Pecker offered to help Cohen find negative stories about Trump’s relationships with women and arrange for them to be bought but never published.

In an interview with Fox News that aired Thursday, Trump said he paid Cohen out of personal funds and the payments were intended to resolve a personal matter, not benefit his campaign.