Aitan Goelman, Mr. Strzok’s lawyer, denounced his client’s dismissal. “The decision to fire Special Agent Strzok is not only a departure from typical bureau practice, but also contradicts Director Wray’s testimony to Congress and his assurances that the F.B.I. intended to follow its regular process in this and all personnel matters,” Mr. Goelman said.

“This decision should be deeply troubling to all Americans,” Mr. Goelman added. “A lengthy investigation and multiple rounds of congressional testimony failed to produce a shred of evidence that Special Agent Strzok’s personal views ever affected his work.”

Mr. Strzok’s text exchanges with Ms. Page demonstrated animosity toward Mr. Trump. In one, Ms. Page asks: Trump is “not ever going to become president, right? Right?!” Mr. Strzok responds: “No. No he won’t. We’ll stop it.” The inspector general, who uncovered the messages, found no evidence that the pair imposed their political views on their investigative decisions but cited that exchange as “not only indicative of a biased state of mind but, even more seriously, implies a willingness to take official action to impact the presidential candidate’s electoral prospects.”

The report by the inspector general, Michael E. Horowitz, that preceded Mr. Strzok’s firing not only criticized his conduct in sending the texts but also his use of personal email accounts to handle sensitive information. In addition, the inspector general criticized Mr. Strzok’s decision not to move swiftly to examine new emails related to the Clinton investigation just weeks before the 2016 election.

Mr. Horowitz said in his report that he was “deeply troubled” by the text messages. Hundreds exchanged over months were found in which the pair disparaged Mr. Trump and, to a lesser extent, Mrs. Clinton, exchanged work gossip and bantered.

On Twitter, Mr. Strzok said he was “deeply saddened by this decision,” adding, “It has been an honor to serve my country and work with the fine men and women of the FBI.”

Mr. Strzok became emblematic of Mr. Trump’s unfounded assertions that a so-called deep state of bureaucrats opposed to him was undermining his presidency. Mr. Trump contended that Mr. Strzok targeted the president and accused Mr. Strzok of being “treasonous” and a “disgrace.” Mr. Strzok told lawmakers that he never leaked information about the Russia inquiry, which could have upended the election and hurt Mr. Trump’s chances of becoming president.