FBI Director James B. Comey was among the senior U.S. officials who had the unpleasant task of traveling to Trump Tower last month to inform the president-elect that Russia had interfered in the election process to help him win office.

Then Comey asked his colleagues — including the CIA director — to step outside so that he could discuss something even more awkward: a dossier in wide circulation in Washington that alleged that Moscow had gathered compromising financial, political and personal material about the incoming U.S. president.

That Comey was asked after that encounter, described by U.S. officials briefed on its details, to stay on as FBI director speaks to his survival instincts and ability to inspire confidence. But the meeting may also have provided a preview of the perilous position he occupies serving in the Trump administration while his agents pursue investigations that seem to lead to the president’s associates.

The news that Comey would stay in place became public Tuesday, some time after he began informing senior FBI officials around the country that he had been asked to continue.

Under normal circumstances, the revelation might have been unsurprising: Comey is less than four years into a 10-year term, and it is extremely rare for a president to remove an FBI director. But President Trump had notably declined to say whether he would keep the FBI director, telling “60 Minutes” in an interview after his election that he wanted to meet with Comey first.

[A brief history of President Trump’s comments about FBI Director Comey]

The FBI and White House declined to comment on Comey’s retention. The New York Times was the first to report on the developments.

Comey has come under fire from both sides of the political aisle in recent months, especially for his handling of the Hillary Clinton email investigation. Many Democrats still blame him for Clinton’s loss, and his decisions to discuss the probe publicly in the final months of the race are being investigated by the Justice Department inspector general.

His greatest looming challenge, however, will be presiding over ongoing investigations whose dimensions and direction are unclear, but which involve Russia’s hacking and interference in the presidential election as well as nebulous ties between Trump associates and Moscow.

Those alleged entanglements continue to expand.

U.S. officials said this week that the FBI has scrutinized communications between Trump’s national security adviser, Lt. Gen. Michael T. Flynn, and Russian ambassador Sergey Kislyak. The two traded texts and phone calls in late December just as the Obama administration was imposing new sanctions on Moscow, raising suspicion that Flynn and Kislyak were improperly discussing the penalties. U.S. officials, who like others spoke on the condition of anonymity to discuss an ongoing investigation, said they have seen no evidence of wrongdoing.

The FBI for several months has been investigating allegations that Trump associates or acquaintances, including his former campaign manager Paul Manafort, might have had improper contact with Russian officials or intermediaries, U.S. officials said.

The bureau is also still examining allegations in the dossier that Comey discussed with Trump in New York last month, according to a U.S. official. The document was assembled by a former British intelligence officer who had been hired by a Washington investigations and political research firm.

The contents of the dossier have been in wide circulation among news organizations and law enforcement entities since mid-2016, but it is unclear if any of its potentially damaging allegations have been substantiated by intelligence agencies.

Sen. John McCain (R-Ariz.) deemed the document troubling enough that he said he had it delivered to Comey. U.S. officials have said that the author of the document is a respected former spy who has helped the FBI on unrelated cases.

Comey, former CIA director John Brennan and former director of national intelligence James R. Clapper Jr. agreed that they should discuss the dossier with Trump even if the allegations were unproven.

The task of having that conversation fell exclusively to Comey, officials said, in part to empty the room of officials, aides and advisers who had taken part in the broader briefing about Russian hacking, but were seen as having no compelling need to be involved in the discussion of the dossier.

The ensuing conversation came with seemingly unavoidable conflicts. It is not clear whether Comey told Trump that the FBI had or was still pursuing allegations made in the dossier, but doing so would have involved telling an incoming president with significant power over the FBI that his associates were potential investigative targets.

At a news conference Monday, White House press secretary Sean Spicer said that Trump “has not made any indication that he would stop an investigation of any sort.”

Trump has railed at the decision by the nation’s intelligence chiefs, including Comey, to attach a copy of the dossier to a report released last month by U.S. spy agencies that concluded that Russian President Vladi­mir Putin had ordered a cyber-campaign to disrupt the election and help Trump.

Trump accused the spy agencies of orchestrating a Nazi-like smear campaign against him. The CIA has been the main target of Trump’s hostility in recent months, but he has also been sharply critical of Comey and the FBI.

In October, Trump implied that Comey was corrupt for saying publicly that the bureau had not found any incriminating information in a belatedly discovered batch of Clinton emails.

But Trump has also praised Comey at times, telling “60 Minutes” that “I respect him a lot.”

At times, it has seemed Comey has few friends in politics. When he announced in July that he was recommending that the Clinton email investigation be closed without charges, Republicans lambasted the FBI director for, in their view, coming to the wrong conclusion on the facts he himself laid out.

Months later, when Comey revealed to Congress that the probe was back on less than two weeks before the election, Democrats excoriated the FBI for violating long-standing Justice Department policies about taking overt steps in an investigation so close to the day when voters would go to the polls.

Even Justice Department officials had advised against Comey taking the actions he did, and Justice Department Inspector General Michael Horowitz is investigating Comey’s conduct in the case. Comey has said he welcomes the review.

The criticism of Comey, though, is not limited to the Clinton investigation. After a recent closed-door briefing from intelligence officials about Russian hacking, some House Democrats called for Comey to resign. They claimed that the FBI director was not treating the Trump-related and Clinton-related investigations the same, particularly in his willingness to discuss the matters publicly.

“He should pack his things and go,” said Rep. Hank Johnson (D-Ga.).

Senate Intelligence Committee leaders have said they will explore for themselves alleged links between Russia and the 2016 political campaigns as part of a wide look at the intelligence community’s report on Russian hacking, and some on the left have called for a special prosecutor to be appointed.

Sen. Jeff Sessions (R-Ala.), Trump’s pick to be attorney general, said in a recent response to a questionnaire that he was “not aware of a basis to recuse myself from such investigations,” though if a “specific matter arose where I believed my impartiality might reasonably be questioned, I would consult with Department ethics officials regarding the most appropriate way to proceed.”

A spokeswoman for Sessions declined to comment for this article.

The law would allow Trump to remove Comey, though a president rarely takes such a step out of respect for the independence of the FBI director’s position. President Bill Clinton removed Director William S. Sessions in 1993 amid allegations of ethical improprieties, making him the only director to be removed from his post by the president since 1972.

Trump greeted Comey warmly at a White House reception on Sunday, shaking the FBI director’s hand, patting him on the back and remarking, “He’s become more famous than me.”

Sari Horwitz contributed to this report.

Read more:

The attorney general could have ordered Comey not to send his bombshell letter on Clinton emails. Here’s why she didn’t.

Why Comey was able to defy Justice bosses on Clinton email announcement