Four months later, Mr. Trump abruptly fired Mr. Comey, setting in motion a cascade of political and legal consequences that led directly to the appointment of Robert S. Mueller III as special counsel overseeing the federal investigation into Russian interference in the 2016 election. Mr. Comey and Mr. Trump have been engaged in a verbal war with each other, often on Twitter, since then.

The 304-page memoir by Mr. Comey is the only firsthand, insider account to emerge so far by a former Trump official describing what it was like to work in the chaotic early days of the administration. In it, Mr. Comey, a veteran law enforcement agent, writes unsparingly about Mr. Trump, calling him a tempestuous president whose connection to honesty was tenuous at best.

“This president is unethical, and untethered to truth and institutional values,” Mr. Comey writes in the book, saying his service to Mr. Trump recalled for him the days when he investigated the mob in New York. “The silent circle of assent. The boss in complete control. The loyalty oaths. The us-versus-them worldview. The lying about all things, large and small, in service to some code of loyalty that put the organization above morality and above the truth.”

With the book’s release set for next week, Mr. Comey is planning a media blitz, beginning with an intensely hyped interview with ABC News that is set to air Sunday night. Republican allies of Mr. Trump’s have already set in motion a counteroffensive, creating a “Lyin’ Comey” website aimed at discrediting the former F.B.I. chief.

Mr. Comey’s book does not include dramatic new revelations about the Russia investigation itself, which is continuing. But Mr. Comey does not pull punches as he provides rigorous detail — pulled from his contemporaneous notes — about his charged interactions with Mr. Trump during the transition and in the White House.