Newly unsealed court documents show that then-candidate Donald Trump communicated repeatedly with his lawyer Michael Cohen amid the election year scramble to keep quiet allegations that Trump previously had an affair with an adult-film actress.

The documents were released Thursday at the direction of a federal judge in New York, who disclosed a day before that an investigation into suspected campaign finance violations had ended. Trump and those close to him long said they were unaware that Cohen had bought the women’s silence, but phone calls and text messages documented by the FBI suggest they were closely involved.

The new details about the investigation are unlikely to have legal consequences for the president or those close to him because the hush-money investigation has concluded. However, the documents could further erode their credibility.

Prosecutors submitted a search warrant from 2018, with newly unredacted sections describing the FBI’s investigation into payments Cohen arranged to two women who claimed to have had affairs with Trump: the porn star Stormy Daniels and a former Playboy model, Karen McDougal.

Cohen, who is serving a three-year prison sentence in a prison north of New York City, pleaded guilty last year to arranging the payments. He also pleaded guilty to violating tax laws, lying to a bank and lying to Congress in statements that concealed the full nature of his efforts to launch a Trump Tower real estate development in Moscow — conversations that continued well into the Republican presidential primary campaign.

From prison, Cohen issued a statement saying: “I and members of The Trump Organization were directed by Mr. Trump to handle the Stormy Daniels matter; including making the hush money payment.” He said the investigation ending without charges for those at Trump’s business “should be of great concern to the American people and investigated by Congress and The Department of Justice.”

The president’s current lawyer, Jay Sekulow, offered a terse comment: “Case closed.”

Rep. Adam B. Schiff (D-Calif.), chairman of the House Intelligence Committee, said the documents show “Donald Trump was intimately involved in devising and executing a corrupt scheme to prevent his affair with Stormy Daniels from being revealed in the final weeks of the 2016 election.”

In a letter to U.S. District Judge William H. Pauley III, prosecutors said the government has “effectively concluded its investigations of (1) who, besides Michael Cohen, was involved in and may be criminally liable for the two campaign finance violations to which Cohen pled guilty; and (2) whether certain individuals [redacted] made false statements, gave false testimony or otherwise obstructed justice in connection with this investigation.”

A person familiar with the investigation, who spoke on the condition of anonymity because they were not authorized to discuss details of the investigation, declined to identify who was once under investigation but said that person was not Trump or any of his family members. The unsealed portion of the search warrants offers new details about the scramble inside Trump’s inner circle to keep quiet any allegations about Trump and Daniels, whose real name is Stephanie Clifford.

“Cohen exchanged a series of calls, text messages, and emails with Keith Davidson, who was then Clifford’s attorney,” as well as officials at the National Enquirer, the supermarket tabloid whose boss, David Pecker, is close to Trump, according to the affidavit of an FBI agent, who added: “Based on the timing of these calls, and the content of the text messages, I believe that at least some of these communications concerned the need to prevent Clifford from going public.”

The Trump campaign was particularly concerned about the accusation because The Washington Post revealed on Oct. 7, 2016, that Trump was caught on an “Access Hollywood” recording referring to women in vulgar terms.

The following day, Cohen received a call from Trump’s spokeswoman at the time, Hope Hicks.

“Sixteen seconds into the call, Trump joined the call, and the call continued for over four minutes,” according to the document.

When Hicks testified before the House Judiciary Committee last month, she said she was “never present” at a time when Cohen and Trump discussed Daniels. She also said she “had no knowledge of Stormy Daniels” during the campaign other than that she had heard her name mentioned as possibly “shopping stories around.”

Asked by congressional investigators why she made statements during the campaign that the president had no relationship with Daniels, she replied, “I was relaying information from the reporter to the different parties involved, primarily Michael and Mr. Trump, and that was the response that was dictated to me. I didn’t ask about the nature of the relationships.”

The House Judiciary Committee is investigating whether Hicks lied to Congress, according to an official with knowledge of the matter who spoke on the condition of anonymity to describe internal discussions. The committee’s chairman, Rep. Jerrold Nadler (D-N.Y.) wrote to Hicks late Thursday demanding that she appear again to clarify the discrepancies between her prior testimony and what was unsealed earlier in the day. A lawyer for Hicks declined to comment.

The Cohen-Trump-Hicks call was followed by calls that evening among Cohen, National Enquirer executives and Hicks.

“At 8:03 p.m., about three minutes after ending his call with Pecker, Cohen called Trump, and they spoke for nearly eight minutes,” the affidavit states.

For days, Cohen negotiated with Daniels’s lawyer to craft a settlement that would buy her silence, according to the court documents. It ended up taking weeks to finalize, with Cohen creating a limited-liability company to make the payment.

At one point, Cohen called Trump immediately after a phone call with Daniels’s lawyer, but the two apparently did not connect, according to the affidavit. Shortly before noon on Oct. 28, 2016, “Cohen spoke to Trump for approximately five minutes. Beginning at 1:21 p.m., Cohen attempted a series of phone calls” to Daniels’s lawyer, Pecker and others.

Cohen arranged a $130,000 payment to Daniels, and on Nov. 1, 2016, the day she received her money, Cohen tried to call Trump but was unsuccessful. According to the affidavit, he then called a number belonging to Kellyanne Conway, Trump’s campaign manager at the time.

They did not connect, but later that evening, “Cohen received a return call from Conway, which lasted for approximately six minutes,” according to the affidavit.

Conway is now a senior White House adviser. A White House spokeswoman did not immediately respond to a request for comment.

In November 2016, the Trump team braced for an expected story in the Wall Street Journal describing how the National Enquirer had shielded Trump from allegations by McDougal, the former Playboy model, that she and Trump once had an affair. The report indicated the tabloid had paid McDougal to bury her story.

In a Nov. 4 text to Dylan Howard, a National Enquirer executive, Cohen wrote: “He’s pissed.” The FBI agent wrote in the affidavit: “I believe Cohen was referring to Trump when he stated ‘he’s pissed.’ ”

Before the Journal story posted online, phone records show Cohen spoke to Hicks and Howard, at one point apparently speaking to both at the same time using separate phones. Twenty minutes before the story was published, Cohen texted Pecker, “The boss just tried calling you. Are you free?”

After the story was published, Cohen and Hicks exchanged messages about its probable effect. “So far I see only 6 stories. Getting little to no traction,” Cohen wrote to her.

“Same. Keep Praying!! It’s working!” she responded.

According to the documents, before the story’s publication, Cohen and Howard texted that they needed McDougal to “disappear” — rather than comment on the arrangement to the Journal.

In a tweet late Thursday, McDougal wrote that she had learned from the release that “powerful men” wanted her to “disappear.” She thanked the judge for “releasing the truth.”

When the Journal reported in January 2018 that Cohen had arranged for Daniels to be paid in the days before the election, Cohen first falsely claimed that he had made the payment on his own without consulting with Trump. Four days before the search warrants were executed, Trump told reporters on Air Force One that he had been unaware of the payments.

Cohen later acknowledged that they were arranged at Trump’s direction. During congressional testimony in February, Cohen released copies of checks he received to reimburse him for the payment, including a check signed by Trump while he was serving as president. Cohen told Congress that he had lied to the public and to first lady Melania Trump about the Daniels matter. Trump, he said, had assured him in an Oval Office meeting in February that he would take care of Cohen’s debt related to Daniels.

“I am going to jail in part because of my decision to help Mr. Trump hide that payment from the American people before they voted a few days later,” he said.

Josh Dawsey and Rachael Weiner contributed to this report.