WASHINGTON — Senior F.B.I. officials who helped investigate Donald J. Trump’s presidential campaign last year wrote in text messages that Hillary Clinton “just has to win” and described a potential Trump victory as “terrifying,” according to texts released Tuesday night.

A top counterintelligence agent, Peter Strzok, exchanged the messages with Lisa Page, a senior F.B.I. lawyer. Some messages criticized Mrs. Clinton’s team, the Obama administration, Congress and other Democrats. But the two appeared appalled at some of Mr. Trump’s comments during the campaign and feared that he would politicize the F.B.I.

For example, after Mr. Trump made an apparent sexual allusion related to the size of his hands, Ms. Page wrote: “This man cannot be president.” In another exchange, Mr. Strzok wrote of a potential Trump presidency, “I’m scared for our organization.” He also referred to Mr. Trump as a “douche.” The messages were turned over to Congress and obtained by The New York Times.

Mr. Strzok went on to become one of the top investigators for the special counsel, Robert S. Mueller III. But over the summer, Mr. Mueller removed Mr. Strzok from his team as soon as he became aware of the texts. Their release is certain to fuel suspicion among Republicans that the investigation into connections between the Trump campaign and Russia was politically motivated from the beginning.