As accounts of past sexual indiscretions threatened to surface during Donald J. Trump's presidential campaign, the job of stifling potentially damaging stories fell to his longtime lawyer and all-around fixer, Michael D. Cohen.

To protect his boss at critical junctures in his improbable political rise, the lawyer relied on intimidation tactics, hush money and the nation's leading tabloid news business, American Media Inc., whose top executives include close Trump allies.

Cohen's role has come under scrutiny amid recent revelations that he facilitated a payment to silence a porn star, but his aggressive behind-the-scenes efforts stretch back years, according to interviews, e-mails and other records.

They intensified as Trump's campaign began in the summer of 2015, when a former hedge-fund manager told Cohen that he had obtained photographs of Trump with a bare-breasted woman. The man said Cohen first blew up at him, then steered him to David J. Pecker, chairman of the tabloid company, which sometimes bought, then buried, embarrassing material about his high-profile friends and allies.

In early 2016, after a legal affairs website uncovered old court cases in which a female former Trump business partner had accused him of sexual misconduct, Cohen released a statement suggesting that the woman, Jill Harth, "would acknowledge" that the story was false. Harth said the statement was made without her permission, and that she stands by her claims. It was not the last time that Cohen would present a denial on behalf of a woman who had alleged a sexual encounter with Trump.

In August of that year, Cohen learned details of a deal that American Media had struck with a former Playboy model, Karen McDougal, that prevented her from going public about an alleged affair with Trump. Cohen was not representing anyone in the confidential agreement, but he was apprised of it by McDougal's lawyer, and earlier had been made aware of her attempt to tell her story by the media company, according to interviews and an e-mail reviewed by the New York Times.

Two months later, Cohen played a direct role in a similar deal involving an adult film star, Stephanie Clifford, who used the stage name Stormy Daniels, and who once said she had had an affair with Trump. Last week, Cohen said he used his own money for the $130,000 payment to her, which has prompted a complaint alleging that Cohen violated campaign finance regulations. Legal experts also have noted that the payment on behalf of his client may have violated New York's ethics rules.

Cohen, who is still described as Trump's personal lawyer although he is no longer on the Trump Organization payroll, has denied any wrongdoing and insists the arrangement was legal. In an interview, he disputed details of some of his other activities that were described to the Times. But he has never shied away from his role as Trump's loyal defender. "It is not like I just work for Trump," Cohen said in an interview in 2016. "I am his friend, and I would do just about anything for him and also his family."

An examination of the efforts to shield Trump from aspects of his own past shows how Cohen maneuvered in the pay-to-play gossip world — populated by porn stars and centerfold models, tabloid editors and lawyers with B- and C-list entertainment clients — that came to unusual prominence in an American presidential election.

Cohen exploited mutual-self interest. By heading off trouble involving Trump's history with women, he accrued loyalty points, the ultimate currency with Trump. He dealt with lawyers who could win fat cuts of any settlements women might reach with American Media or with Trump.

At least two women got money and, in McDougal's case, a promise of favorable attention in American Media publications, which include the National Enquirer, Star, Us Weekly and Radar. Trump, of course, benefited the most: avoiding more scrutiny as he struggled to dismiss multiple allegations of groping and unwanted advances that arose during the campaign.

One American Media executive, in a 2016 interview, said that the priority was that nothing embarrassing come out. But in the gossip economy, secrets last only as long as the incentives to keep them do.

Risqué photos

It was July 2015 when Cohen received a phone call from Jeremy Frommer, a hedge-fund manager turned digital entrepreneur, who had obtained photos of Trump appearing to autograph the breasts of a topless woman from the estate of Bob Guccione, the founder of Penthouse magazine. Cohen was not pleased.

"He was in a rage," Frommer said in an interview. "He's like, 'If you show those photos, I'm gonna take you down.' "

It was the rough talk of a Long Island native who started his career juggling work as a personal injury lawyer and taxi fleet manager and met Trump after acquiring units in Trump buildings.

After Cohen joined the Trump Organization in 2006, the role that Trump wanted him to play was clear: a combination of aggressive spokesman and lieutenant who would take on the real estate mogul's antagonists. It was a job Roy Cohn, a New York lawyer best known for advising Sen. Joseph McCarthy, had done decades earlier for Trump. Cohen's work for his boss was often a mystery even to others in his office, but his devotion was clear.

In talking with Cohen, Frommer mentioned Pecker. Years earlier, Frommer had sold American Media the exclusive rights to a suggestive photograph of Arnold Schwarzenegger — which it did not publish — and he knew the company's chief executive.

Frommer recalled Cohen's saying, "Yeah, I know Pecker." Frommer added, "That's where the conversation calmed down."

Pecker and Trump, a staple of the American gossip media since the 1980s, have a friendship that goes back decades. The relationship benefited Trump throughout the campaign as the Enquirer lionized him and hammered rivals like Ted Cruz, Ben Carson and, finally, Hillary Clinton.

Cohen formed his own bond with Pecker, keeping in touch with him and Dylan Howard, a top executive, throughout the campaign.

American Media acknowledged those ties, saying in a statement, "Michael Cohen and President Trump have been personal friends of Pecker's for decades." But, it said, neither of them "nor any other individual has attempted to, or ever, influenced (or will ever influence) coverage at A.M.I.'s publications. Period."

After the initial blowup, Frommer said, he and Cohen quickly agreed that Frommer would take the Trump photos to Pecker. The men soon began discussing potential business deals, including an interview with Trump as part of a joint project between American Media and Frommer's company, Jerrick Media, according to text messages and e-mails reviewed by the Times.

"Spoke to Cohen we are set. Well done!" Pecker told Frommer in a July 2015 text exchange.

Two months later, when Frommer expressed doubt that the Trump interview would take place, Cohen responded in an Oct. 5 e-mail: "No no … relax. I am on it and will make it happen."

Frommer said he had assured Cohen at the time that he wouldn't make the photos public — "I said, 'Don't worry, I'm not going to publish them' " — but that the decision had nothing to do with the business talks.

In the end, American Media concluded that the photos were of little value. The interview and the deals never materialized for Frommer, who went on to publish one of the Trump photos on his own website.

American Media said in a statement that it had no interest in suppressing the photographs. But in early 2016, an American Media executive, speaking only on condition of anonymity in discussing internal company thinking, said that when the negotiations between A.M.I. and Frommer began, they were intended to suppress the photos, part of broader efforts by American Media to "catch and kill" information that would damage Trump.

In an interview Friday, Cohen acknowledged directing Frommer to A.M.I., but said he did so not because of photographs of Trump but for other photos of "another notable individual that I had no interest in seeing or wanting."

Back then, however, Cohen acknowledged that he had been eager to keep the photos hidden. " Trump has a family," he said. "I felt like I had to protect his family."

A Playmate's story

For Cohen and Trump, American Media was more than a company they could rely on for friendly coverage. It was also where people looking to sell potentially damaging information about Trump were likely to turn.

In the summer of 2016, American Media came to Cohen with a story involving McDougal, the former Playboy Playmate. She claimed to have had a consensual affair with Trump in the mid-2000s, early in his marriage to Melania Trump. Trump denies an affair.

McDougal had retained Keith Davidson, a Hollywood lawyer, who reached out to contacts at American Media. After negotiating on and off for a couple of months, A.M.I. agreed to give McDougal $150,000 for the exclusive rights to her story, along with promises of publicity and marketing opportunities through its fitness magazines. The contract did not identify Trump, but required her to keep quiet about any relationship with a married man.

A.M.I. had shared her allegations with Cohen, though it said it did so only as it worked to corroborate her claims, which it said it ultimately could not do. But that was not the only heads-up Cohen received.

Soon after McDougal signed the confidential agreement on Aug. 5, 2016, Davidson e-mailed Cohen, "Michael, please give me a call at your convenience." Davidson followed up by explaining to Cohen over the phone that the McDougal transaction had been completed, according to a person familiar with the conversation. Cohen said, "I don't recall those communications."

Davidson acknowledged the public's interest in Clifford's and McDougal's stories, but said that he was "not at liberty to discuss private client information."

In the months after McDougal's agreement with A.M.I., Trump's relationships with women drew more scrutiny on the campaign trail. The release of an audio recording that captured the candidate bragging about grabbing women's genitals inspired numerous women to step forward with allegations that he had groped or kissed them against their will.

According to people in contact with her at the time, McDougal expressed frustration with what she viewed as foot-dragging by A.M.I. in fulfilling commitments made in her contract and with Davidson's lackluster response to her. She reached out to a prominent First Amendment lawyer, Theodore J. Boutrous Jr., who had made a public pledge in October 2016 to defend anyone threatened with legal action by Trump for making allegations against him. Boutrous briefly represented McDougal, focusing primarily on her restrictive contract with A.M.I., which in late November 2016 agreed she could respond to "legitimate" press inquiries about the alleged affair.

McDougal's story eventually became public, in a Wall Street Journal article published days before the election. The New Yorker published new details, including an interview with her, last week.

Quelling a Storm

Over the years Cohen had come to know McDougal's lawyer, Davidson, well enough that when New York magazine profiled Davidson last week, Cohen offered an enthusiastic endorsement: "He has always been professional, ethical and a true gentleman." (The California State Bar suspended Davidson's law license for 90 days in 2010, for four counts of misconduct.)

Davidson's client list had included the professional athletes Jalen Rose and Manny Pacquiao, as well as gossip-page regulars who placed him in the middle of the sex-tape cases of the "Austin Powers" actor Verne Troyer, the wrestler Hulk Hogan and the onetime Playboy model and MTV host Tila Tequila. He was a natural choice for Clifford, also known as Stormy Daniels, when she sought to sell her own Trump story.

She was alleging that she had had a consensual sexual relationship with Trump after they met at a celebrity golf tournament about 10 years earlier. Trump denies her claims

Just two months after McDougal's story was effectively muted by her contract with American Media, Davidson set about brokering the silence of the adult film actress. This time, the negotiator on the other end of the transaction was Cohen.

The actress agreed to a $130,000 settlement in mid-October 2016 in exchange for keeping quiet, according to contracts seen by the Times and people familiar with the matter. To make the payment, Cohen created a Delaware limited liability company called Essential Consultants, news of which was first reported by the Wall Street Journal last month, and he claimed in a statement first released to the Times last week that the money came from his own pocket.

Clifford has suggested in recent days that she believes Cohen has breached that agreement and that she is preparing to speak out. In 2011, she had told her story about Trump to two gossip publications. One of them, In Touch magazine, did not publish the story after Cohen warned that he would pursue aggressive legal action, the Associated Press reported last month.

The other outlet, The Dirty, took down a brief story after Davidson threatened legal action just a day after his client had provided information to the website, according to Nik Richie, The Dirty's founder, and a letter seen by the Times.

After the deal between McDougal and A.M.I. was completed, Davidson regularly exchanged e-mails, text messages and calls with Cohen, according to people familiar with the contacts, including last week, when Davidson publicly bolstered Cohen's statement that he had paid Clifford himself.

Cohen went on to steer a new client to Davidson, Chuck LaBella, a former NBC executive who worked closely with Trump on "The Apprentice" and the "Miss USA" pageant. LaBella had become the object of an intense Twitter campaign — led by the comedian and ardent Trump critic Tom Arnold — calling upon him to share anything he might know about misbehavior by Trump. He became a client of Davidson last fall, according to people familiar with the arrangement.