Then-candidate Donald Trump spoke with lawyer Michael Cohen several times before and after the attorney paid porn star Stormy Daniels to keep her from going public with her claim of an affair with Trump, according to an FBI affidavit made public Thursday.

Two of the phone conversations took place on Oct. 8, 2016, the day after the leak of the “Access Hollywood” tape on which Trump was heard making crude comments about women, according to the document.

The first of those calls, the document states, was a three-way chat with Trump’s then-campaign press secretary, Hope Hicks, who last month refused to answer questions from congressional Democrats about her time as White House communications director.

Trump’s discussions with Cohen were among a “series of calls, text messages and emails” involving Cohen and others, including a lawyer for Daniels, whose real name is Stephanie Clifford, according to the April 8, 2018, affidavit.

“Based on the timing of these calls, and the contents of the text messages and emails, I believe that at least some of these communications concerned the need to prevent Clifford from going public, particularly in the wake of the Access Hollywood story,” wrote an FBI agent whose name was redacted.

The affidavit also alleged that Trump and Cohen spoke by phone on the morning of Oct. 28, 2016 — one day after Cohen wired $130,000 to Daniels’ lawyer — and that Cohen tried to reach Trump again that evening but instead spoke with Trump’s then-campaign manager, ­Kellyanne Conway.

Trump defeated Hillary Clinton to win the presidency less than two weeks later. He has denied having an affair with Daniels, who claims it took place in 2006.

The affidavit — part of an application for a search warrant to raid Cohen’s office, home and hotel room — was contained in 897 pages of court records tied to the federal prosecution of Cohen.

Cohen is serving three years in prison for a slew of crimes that include violating campaign-finance laws by making the ­hush-money payment to Daniels.