Donald J. Trump watched anxiously from the White House in April 2018 as news broke about federal agents searching the home of Michael D. Cohen, the man entrusted to conceal some of the president’s deepest secrets. After initially coming to Mr. Cohen’s defense, Mr. Trump washed his hands of his fixer within weeks, brushing aside Mr. Cohen’s feelers about a pardon and disavowing his legal bills.

Mr. Trump took a different tack when prosecutors shifted their scrutiny to Allen H. Weisselberg, the Trump family’s longtime financial gatekeeper. Mr. Trump’s company paid Mr. Weisselberg’s legal bills and awarded him a $2 million severance, with a condition: He could not voluntarily cooperate with any law enforcement agency.

After Mr. Weisselberg signed the deal last year, Mr. Trump’s lawyers privately pressed him to testify in a civil fraud case filed against the former president, hoping the finance chief’s testimony would aid their defense, according to people with knowledge of the discussions, which have not previously been reported. But prosecutors say Mr. Weisselberg lied during his testimony, and this month he pleaded guilty to perjury.

The fixer and the moneyman both landed behind bars. But while Mr. Weisselberg remained loyal, refusing to implicate his boss, Mr. Cohen is poised to become a central witness for the Manhattan district attorney at Mr. Trump’s criminal trial next month, the first prosecution of a former U.S. president.

The contrasting cases of Mr. Cohen and Mr. Weisselberg — detailed in court records and interviews with 18 people directly involved in the cases, some of whom requested anonymity to discuss confidential conversations — demonstrate the power and peril of Mr. Trump’s tactics for avoiding a crisis like the one he now faces. The trial is the realization of Mr. Trump’s long-held fear that prosecutors would flip trusted aides into dangerous witnesses.

The former president, facing four indictments and several lawsuits while seeking to reclaim the White House, careens from one case to the next, seeking to exert control over witnesses. In screeds posted on his social media site, he mixes enticements with threats, praise with scorn, and when all else fails, he makes life miserable for anyone audacious enough to cross him.