WASHINGTON — By the end, neither of them thought much of the other.

After President Trump accused his predecessor in March of wiretapping him, James B. Comey, the F.B.I. director, was flabbergasted. The president, Mr. Comey told associates, was “outside the realm of normal,” even “crazy.”

For his part, Mr. Trump fumed when Mr. Comey publicly dismissed the sensational wiretapping claim. In the weeks that followed, he grew angrier and began talking about firing Mr. Comey. After stewing last weekend while watching Sunday talk shows at his New Jersey golf resort, Mr. Trump decided it was time. There was “something wrong with” Mr. Comey, he told aides.

The collision between president and F.B.I. director that culminated with Mr. Comey’s stunning dismissal on Tuesday had been a long time coming. To a president obsessed with loyalty, Mr. Comey was a rogue operator who could not be trusted as the F.B.I. investigated Russian ties to Mr. Trump’s campaign. To a lawman obsessed with independence, Mr. Trump was the ultimate loose cannon, making irresponsible claims on Twitter and jeopardizing the bureau’s credibility.