WASHINGTON — An FBI agent removed from special counsel Robert Mueller’s investigative team over politically charged text messages referred to Donald Trump, then the Republican presidential candidate, as an “idiot” and said on election night that a Trump victory would be “terrifying,” according to dozens of text messages reviewed by The Associated Press.

Peter Strzok, a veteran FBI counterintelligence agent who was also deeply involved in the investigation into Democrat Hillary Clinton’s use of a private email server, was removed over the summer from Mueller’s team following the discovery of text messages exchanged with Lisa Page, an FBI lawyer who was also detailed to the group of agents and prosecutors investigating potential coordination between Russia and the Trump campaign.

The messages, which surfaced in a Justice Department inspector general investigation into the FBI’s handling of the Clinton inquiry, were being provided to congressional committees and were reviewed by the AP on Tuesday night.

The texts seen by the AP occurred as the 2016 presidential race was in full swing and as Trump and Clinton were looking to defeat their primary challengers and head toward the general election. The messages cover a broad range of political topics and include an exchange of news articles about the race, often alongside their own commentaries.

In one exchange, on Oct. 18, 2016, Strzok writes to Page and says: “I am riled up. Trump is an (expletive) idiot, is unable to provide a coherent answer. I CAN’T PULL AWAY. WHAT THE (expletive) HAPPENED TO OUR COUNTRY??!?!

Weeks later, on election night, as it becomes clearer that Trump might defeat Clinton, he says, “OMG THIS IS (expletive) TERRIFYING.”

Page replies: “Yeah, that’s not good.”

A spokesman for Mueller has said Strzok was removed from the team as soon as the text messages were discovered. Nonetheless, Trump and other Republicans have held up the revelation to suggest that members of Mueller’s team, and members of the FBI leadership in general, are politically compromised.

FBI Director Chris Wray tacitly rebuked the president at a hearing last week in which he defended his agents.