NEW YORK — Court records show that in the days leading up to the 2016 election, President Donald Trump spoke with aides rushing to squash stories about alleged affairs he had.

Search warrants unsealed Thursday shed new light on the president’s role as his campaign scrambled to respond to media inquiries about hush-money paid to two women who said they had affairs with Trump.

U.S. District Judge William Pauley ordered the materials unsealed this week after prosecutors said they had concluded their investigation into a scheme intended to protect Trump’s reputation as he ran for president.

The investigation involved payments Cohen helped orchestrate to porn actress Stormy Daniels and Playboy centerfold Karen McDougal after they claimed they had affairs with Trump.

Trump denies the allegations.

Cohen later pleaded guilty to campaign finance violations. He is serving a three-year sentence.