When the FBI tapped him to investigate whether the Trump campaign conspired with Russia to shape the presidential election, agent Peter Strzok was thrilled.

“And damn this feels momentous,” Strzok wrote to an FBI lawyer in July 2016. “Because this matters.”

At that point, the task ahead did not seem too daunting for the celebrated counterintelligence investigator who had spent decades busting terrorists and spies. Donald Trump, a former reality-TV star and the Republican nominee for president, seemed unlikely to win the election. The FBI’s examination of his campaign was a secret. And the public pressure that Strzok faced in his last politically charged case — the investigation of Trump’s opponent, Hillary Clinton — was not quite so intense.

But by the following spring, everything had changed. Trump upset Clinton in the November election, and the FBI director said publicly that the president’s campaign was being examined. A special counsel was appointed to lead the high-stakes case.

Strzok confided in friends that his early enthusiasm had abated.

“The impression I got was that he didn’t want to go and get involved in some political thing that was going to drag out forever and have nothing come of it,” said a former FBI official who discussed the case with Strzok.

The case would come to upend Strzok’s life — airing to the world his marital infidelity and bringing his distinguished, 22-year FBI career to an ignominious end.

Last week, Strzok was fired from the bureau over text messages he sent expressing his disdain for Trump and suggesting he would “stop” the Republican candidate from winning the election.

The termination — ordered personally by the bureau’s deputy director — comes as the FBI is struggling to improve morale and regain its once venerated reputation amid constant criticism from the president and his conservative allies.

But Strzok’s firing, rather than easing tensions, might serve to fuel the partisan inferno surrounding the bureau’s work.

Strzok has been one of President Trump’s favorite targets as he has sought to undercut the ongoing investigation into his campaign.

That seems to have influenced the bureau’s treatment of the once-beloved agent, defenders of Strzok say.

“It is a decision that produces only one winner — those who seek to harm our country and weaken our democracy,” Aitan Goelman, Strzok’s attorney, said in a statement about his client’s firing.

FBI Director Christopher A. Wray has said Strzok’s discipline would be handled “by the book.” But the termination was more severe than the demotion and 60-day suspension that the bureau’s employee discipline office decided Strzok should face. The FBI declined to comment.

Many people who worked with Strzok over the years said they did not know what his partisan leanings were until the messages emerged. But even supporters acknowledge his reputation might have sustained a fatal wound from his texts about people he was investigating, on a work phone, to a woman with whom he was having an affair.

“I never saw the political side that’s in his texts, and I mean that,” said Robert Anderson, a former FBI executive who worked with Strzok. “However, I also told him to his face since this happened, ‘Look, I love you, brother, but you stepped in it here.’ ”

A high-profile assignment

Strzok has always seemed to live a life fit for a G-man movie. The son of an Army officer turned international development worker, Strzok traveled the world as a child — witnessing violent revolts against governments in Iran, West Africa and Haiti by the time he was 16.

Strzok served briefly in the Army himself, spending four years in the early 1990s as an active-duty field artillery officer. Fred Dews, who trained with him in the Army and ROTC, remembered him as a young man of “quiet intensity.” At field artillery school in Oklahoma, Strzok finished at the top of his class, Dews said.

Strzok joined the FBI in 1996, working first as an analyst on terrorism cases and later as a special agent in Boston and Washington. He came to specialize in espionage and counterintelligence work.

“He was beloved by the agents on his squad, and you could tell he was going places,” said Ryan Fayhee, a former Justice Department prosecutor who worked with Strzok. “As someone who has seen him operate for more than a decade, he was by far the best leader that I’d met in the FBI, and he had the most success of any counterintelligence agent.”

No matter where Strzok was assigned, he found himself at the center of the biggest cases. He located the rental car abandoned by three of the 9/11 hijackers, helped arrest Russian spies living a secret life in the United States and supervised sensitive probes of CIA officers thought to have abused their positions.

Strzok’s colleagues in federal law enforcement said he had a special talent for following leads and marshaling the bureaucratic machinery of the FBI into action.

In 2011, for example, a guard at a U.S. Consulate was indicted on a charge of trying to sell secrets to China. The guard, Bryan Underwood, skipped a court appearance, leaving behind what appeared to be a suicide note.

Strzok learned that Underwood had possibly been spotted riding a bicycle along a Virginia highway, according to people familiar with the case. Strzok worked through the night, gathering bus travel records, Internet browser histories and other details that made him think the suspect had used a fake name to travel to a Los Angeles hotel previously linked to Chinese intelligence agents, these people said.

As the sun came up in Washington and Strzok was still at his desk, he sent FBI agents to the hotel room where he thought Underwood was staying.

Strzok was right. When Underwood was arrested, he was traveling with more than $10,000 in cash and 80,000 Japanese yen, authorities said.

Following that, Strzok tackled one of the most controversial counterintelligence cases the FBI had handled in years — the probe into John Kiriakou, a former CIA officer who ultimately pleaded guilty to disclosing to a reporter information about an undercover CIA officer.

Some in the bureau say the investigation — which was complicated because it related to the defense lawyers involved in military commission trials of al-Qaeda terrorist suspects at Guantanamo Bay, Cuba — helped cement Strzok’s reputation. Kiriakou was charged within days of an interview that Strzok supervised, and he ended up serving nearly two years in prison.

For Kiriakou, though, Strzok’s woes are a long-overdue comeuppance.

“There are so many people in the federal intelligence community who are cowboys, and they think because they are the good guys they can do anything they want,” Kiriakou said. “Sometimes karma comes back to bite them.”

In 2015, Strzok was tapped for a supervisory role on the small team at FBI headquarters assigned to investigate Clinton’s handling of classified information as secretary of state. The work would put him in close contact with a lawyer in the deputy director’s office, Lisa Page, with whom he would soon begin sharing views that he kept secret even from those closest to him in the bureau. Unbeknown to their colleagues, they were having an affair.

'They don't givea rip about politics'

As the FBI’s investigation of Clinton trudged forward and cast a significant shadow over the Democrat’s campaign, then-FBI Director James B. Comey addressed the matter in a briefing with reporters. “If you know my folks,” he said, “you know they don’t give a rip about politics.”

For Strzok and Page, that did not seem to be true.

Over thousands of text messages, the two ripped politicians of all stripes. Strzok derided Martin O’Malley, the Democratic former governor of Maryland and a primary opponent of Clinton, as a “freakshow.” He described Sen. Bernie Sanders (I-Vt.), another Clinton primary opponent, as an “idiot like Trump.” Page said she hoped House Speaker Paul D. Ryan (R-Wis.) “fails and crashes in a blaze of glory.” Strzok responded: “Yes. And, me too. At some point the Rep party needs to pull their head out of their *ss.”

In March 2016, Strzok wrote to Page, “God Hillary should win 100,000,000 – 0.”

If the pair’s political leanings crept into their work, though, that was not obvious to those involved with the Clinton case. One person on the team said he “had no idea what Pete’s political leanings were, at all, and in fact, I would have assumed that they would have been more conservative, given that 95 percent of the bureau is more conservative.”

The person, who like others spoke on the condition of anonymity to discuss ongoing cases and sensitive personnel issues, said Strzok seemed “somewhat offended” by Clinton’s cavalier attitude toward her emails and advocated for aggressive steps to advance the case.

In July 2016, Comey announced at a news conference at FBI headquarters that the bureau was recommending Clinton not face any charges. His statement — which Strzok helped craft — stunned even his Justice Department bosses.

When the FBI recommends cases be closed, officials typically make no statement at all. The decision to charge someone is up to prosecutors, and the FBI is supposed to make its view known only to them. Comey’s announcement was also unusual in that it lambasted Clinton for being “extremely careless” — words that Strzok advised using — in her use of a private email server.

Strzok would move on to the Russia investigation, but the Clinton case was not yet done. In October, Comey revealed that investigators had resumed their work after discovering emails potentially relevant to the case on the laptop of disgraced former congressman Anthony Weiner (D-N.Y.), the husband of one of Clinton’s top aides. Though the bureau only days later said investigators had found nothing to make them change their minds, its actions upended the presidential election.

A few weeks later, Clinton lost.

In January 2017, the Justice Department’s inspector general, Michael E. Horowitz, initiated a broad review of the Clinton case — the handling of which was by then drawing criticism from all quarters. Democrats accused Comey of costing Clinton the presidency. Republicans complained that Clinton should have been charged.

The bureau was thrown into upheaval. Trump fired Comey as FBI director in May 2017 — citing his handling of the Clinton case but acknowledging in a television interview he had the Russia investigation on his mind when he did so. Deputy Attorney General Rod J. Rosenstein appointed former FBI director Robert S. Mueller III as special counsel to explore Russian interference in the election and possible Trump connections.

Strzok had been leading that work for the FBI and was an obvious pick for Mueller’s team.

'We'll stop it'

Text messages show that Strzok and Page, who both for a time served on Mueller’s team, wrestled with whether they should again work together on such a high-profile case. Two people familiar with their relationship said that, by then, their affair had ended. One of the people said Page discouraged Strzok from joining the team, thinking that would be best for his career.

“Lisa, I’m PULLED to the mission and the team, for the right reasons,” Strzok wrote in June 2017. “You saw it! You know what it is in me and that it’s pure and I’m good and you admire it!”

“It doesn’t NEED you,” Page responded. “And I don’t care if it does. Every conversation I’ve had with you about this still stands, and now I’ve asked you, begged you, not to. You do what you want.”

In conversations with others, Strzok said he might feel “relieved” to be taken off the case.

By that time, Horowitz was well into his investigation of the Clinton email case. As his investigators sifted through thousands of text messages, they would soon zero in on Strzok and Page.

Horowitz did not find the most worrisome exchange until later — when Page, in August 2016, told Strzok that Trump was “not ever going to become president, right? Right?!”

“No. No he’s not. We’ll stop it,” Strzok responded.

But what Horowitz had found by the summer of 2017 was damaging enough. Strzok had called Trump an idiot and forwarded a story about Clinton possibly losing the election with a note that used an expletive and said the prospect was “TERRIFYING.”

On July 27 of that year, Horowitz briefed Rosenstein and Mueller on the messages. The next day, Strzok was summoned to the special counsel’s office, where Mueller told him he could no longer participate in the case. He was reassigned to a position in human resources.

Horowitz would ultimately say that he could not connect texts with specific investigative decisions in the Clinton case and that he could find “no evidence” that bias affected the decision not to prosecute Clinton. But in June of this year — after the inspector general alleged Strzok had implied “a willingness to take official action” to hurt Trump’s chances of being president — Strzok was made to turn in his gun and badge while the bureau moved to fire him.

Strzok denies trying to use his position to prevent Trump’s election. He has said the comment about his stopping Trump came after the candidate had attacked the father of a slain U.S. soldier. Strzok said he assumed that “the American population would not elect somebody demonstrating that behavior to be president of the United States.”

Strzok’s defenders agree that he could not stay on the Russia case when the texts surfaced.

“It was painful and it was too bad, but everybody understands that he had to be removed from Mueller’s team,” said Fayhee, the former prosecutor.

One former FBI official who remains close with Strzok said Strzok told him Mueller “did the right thing” in removing him from the team, because even the appearance that he was biased might shake public confidence in the work. But Strzok, those who know him say, hoped to finish his career and retire from the FBI and now feels he is being unfairly vilified by those with political agendas.

Strzok, who declined to comment through his attorney for this report, still hopes to restore his reputation, friends say. His team started a GoFundMe page, which raised tens of thousands of dollars after his firing became public Monday. But even supporters say he faces an uphill battle to be welcomed into the community of former FBI agents.

“He’s being judged on the last two years of all this stuff,” said one friend and former FBI official. “I’m not saying that’s fair, but I’m not saying it’s going to change.”