WASHINGTON — An FBI agent whose anti-Trump text messages fueled suspicions of partisan bias said at a fiery and occasionally chaotic hearing in Congress on Thursday that his work has never been tainted by politics, angrily rejecting Republican allegations that he set out to stop Donald Trump from becoming president.

Peter Strzok testified publicly for the first time since being removed from special counsel Robert Mueller's team, telling lawmakers that texts he traded with an FBI lawyer in the run-up to the 2016 presidential election reflected personal views that he never once acted on.

"At no time, in any of those texts, did those personal beliefs ever enter into the realm of any action I took," Strzok said.

The hearing brought a defiant Strzok face-to-face with Republican lawmakers who for months have held up his texts as the embodiment of anti-Trump bias within the FBI. In breaking his months-long silence, Strzok vigorously defended his handling of two hugely sensitive investigations in which he played a leading role: inquiries into Hillary Clinton's email use and possible coordination between the Trump campaign and Russia.

He insisted the FBI had good cause two years ago to start investigating whether the Trump campaign was working with the Kremlin amid allegations of what he described as a Russian offer of assistance to a Trump campaign associate. He characterized anti-Trump text messages with an FBI lawyer as personal communications that he never envisioned becoming public and denied that they had swayed his actions.

Strzok insisted under aggressive questioning that a much-discussed August 2016 text in which he said "We'll stop" a Trump presidency followed Trump's denigration of the family of a dead U.S. service member. He said the text, written late at night and off-the-cuff, reflected his belief that the American public would not stomach such "horrible, disgusting behavior" by the Republican presidential candidate.

But, he added in a raised voice and emphatic tone, "It was in no way — unequivocally — any suggestion that me, the FBI, would take any action whatsoever to improperly impact the electoral process for any candidate. So, I take great offense, and I take great disagreement to your assertion of what that was or wasn't.

Plus, he said, both investigations were handled by large teams.

"They would not tolerate any improper behavior in me anymore than I would tolerate it in them," Strzok said. "That is who we are as the FBI. And the suggestion that I, in some dark chamber somewhere in the FBI, would somehow cast aside all of these procedures, all of these safeguards and somehow be able to do this is astounding to me. It simply couldn't happen."

Some Democrats applauded after he finished speaking.

Republican members of the House judiciary and oversight committees grilled Strzok as they argued that text messages with FBI lawyer Lisa Page colored the outcome of the Clinton investigation and undercut the ongoing Russia probe. Strzok, a seasoned counterintelligence agent, helped lead both investigations but has since been reassigned to human resources.

"Agent Strzok had Hillary Clinton winning the White House before he finished investigating her," said Rep. Trey Gowdy, Republican chairman of the House Oversight and Government Reform Committee. "Agent Strzok had Donald Trump impeached before he even started investigating him. That is bias. Agent Strzok may not see it but the rest of the country does, and it is not what we want, expect or deserve from any law enforcement officer much less the FBI."

The hearing briefly devolved into chaos and open yelling as Judiciary Committee Chairman Robert Goodlatte said Strzok needed to answer Republicans' questions and suggested they might recess the hearing and hold him in contempt. Democrats objected to Goodlatte's repeated attempts to get Strzok to answer. Goodlatte eventually let the hearing proceed without calling the panel into recess.

In his opening statement, Strzok said he has never allowed personal opinions to infect his work, that he knew information during the campaign that had the potential to damage Trump but never contemplated leaking it and that the focus on him by Congress is misguided and plays into "our enemies' campaign to tear America apart."

Strzok acknowledged that while his text message criticism was "blunt," it was not directed at one person or political party and included jabs not only at Trump but also at Clinton and Sen. Bernie Sanders.

"Let me be clear, unequivocally and under oath: Not once in my 26 years of defending my nation did my personal opinions impact any official action I took," he said.

He said he was one of the few people during the 2016 election who knew the details of Russian election interference and its possible connections with people in the Trump orbit, and that that information could have derailed Trump's election chances. "But," he said, "the thought of exposing that information never crossed my mind."

Although Strzok has said through his lawyer that he was eager to tell his side of the story, he made clear his exasperation at being the focal point of a congressional hearing at a time when Russian election interference has been successfully "sowing discord in our nation and shaking faith in our institutions."

"I have the utmost respect for Congress's oversight role, but I truly believe that today's hearing is just another victory notch in Putin's belt and another milestone in our enemies' campaign to tear America apart," Strzok said. "As someone who loves this country and cherishes its ideals, it is profoundly painful to watch and even worse to play a part in."

The contentious hearing follows hours of closed-door questioning last week. It also reflects an effort to shift attention away from the content of Strzok's texts and onto what he says is the more pressing issue: the Russians' "grave attack" on American democracy and continuing efforts to divide the country.

Republicans eager for ways to discredit Mueller's investigation have for months held up the texts from Strzok and Page to support allegations of anti-Trump bias within federal law enforcement.

The Justice Department's inspector general has criticized Strzok and Page for creating the appearance of impropriety. But the report said it found no evidence of political bias in the FBI's decision not to pursue criminal charges against Clinton. And many Democrats say actions taken by law enforcement during the campaign season, including announcing a reopening of the investigation into Clinton just days before the election, actually wound up harming the Democratic candidate and aiding the Republican candidate, Trump.

FBI Director Chris Wray says employees who were singled out for criticism in the report have been referred to internal disciplinary officials. Strzok's lawyer has said he was escorted from the FBI building as the disciplinary process winds its way through the system.

Page is expected to speak to lawmakers at a private meeting Friday.

___

Associated Press writer Chad Day in Washington contributed to this report.