Donald J. Trump has always surrounded himself with lawyers — all types of lawyers. There are the television-friendly talking heads. The polished criminal practitioners. The pit-bull litigators, the corporate suits and the legal advisers with their own legal troubles.

And then there was the singular Michael D. Cohen, lawyer by trade and enforcer by nature. With the loyalty of a surrogate son, he kept Mr. Trump’s secrets and cleaned up his messes. He was the fixer.

This week, however, Mr. Cohen is poised to unfix Mr. Trump’s life. When he takes the stand as a vital witness at Mr. Trump’s criminal trial in Manhattan, Mr. Cohen will unearth some of the secrets he buried, revealing a mess that prosecutors say his former boss was desperate to hide.

It will represent a pivotal moment of the trial, and the climax of a decades-long relationship between two New York loudmouths who used each other, betrayed each other and will now face off on the biggest stage: The first criminal trial of an American president.

Interviews with 10 of Mr. Cohen’s allies and adversaries, as well as a review of court records and Mr. Cohen’s books, paint a portrait of a once-obscure operator who came to play an outsized role in American politics, a man whose relationship with the former president traced an arc from asset to threat.