WASHINGTON — President Donald Trump called the FBI director, James B. Comey, weeks after he took office and asked him when federal authorities were going to put out word that Trump was not personally under investigation, according to two people briefed on the call.

Comey told the president that if he wanted to know details about the bureau's investigations, he should not contact him directly but instead follow the proper procedures and have the White House counsel send any inquires to the Justice Department, according to those people.

After explaining to Trump how communications with the FBI should work, Comey believed he had effectively drawn the line after a series of encounters he had with the president and other White House officials that he felt jeopardized the FBI's independence. At the time, Comey was overseeing the investigation into links between Trump's associates and Russia.

Those interactions included a dinner in which associates of Comey say Trump asked him to pledge his loyalty and a meeting in the Oval Office at which Trump told him he hoped Comey would shut down an investigation into Trump's former national security adviser, Michael T. Flynn. Trump has denied making the request.

The day after the Flynn conversation, Reince Priebus, the White House chief of staff, asked Comey to help push back on reports in the news media that Trump's associates had been in contact with Russian intelligence officials during the campaign.

Comey described all of his encounters with the president and the White House — including the phone call from Trump — in detailed memos he wrote at the time and gave to his aides. Congressional investigators have requested copies of the memos, which, according to two people who have read them, provide snapshots of a fraught relationship between a president trying to win over and influence an FBI director, and someone who had built his reputation on asserting his independence, sometimes in a dramatic way.

Sean Spicer, the White House press secretary, said in a statement Thursday that "the sworn testimony" of both Comey and Andrew G. McCabe, the FBI's acting director, "make clear that there was never any attempt to interfere in this investigation. As the president previously stated, he respects the ongoing investigations and will continue working to fulfill his promises to the American people."

It is not clear whether in all their interactions Comey answered Trump's question or if he ever told him whether he was under investigation. In the letter Trump sent to Comey last week in which he informed him that he had been fired, Trump told Comey, "I greatly appreciate you informing me, on three separate occasions, that I am not under investigation."

The FBI's longest-running director, J. Edgar Hoover, had close relationships with several presidents. But in the modern FBI, directors have sought an arm's length relationship with the presidents they serve and have followed Justice Department guidelines outlining how the White House should have limited contact with the FBI.

Those guidelines, which also cover the FBI, prohibit conversations with the White House about active criminal investigations unless they are "important for the performance of the president's duties and appropriate from a law enforcement perspective." When such conversations are necessary, only the attorney general or the deputy attorney general can initiate those discussions.

Comey has spoken privately of his concerns that the contacts from Trump and his aides were inappropriate, and how he felt compelled to resist them.

"He had to throw some brushback pitches to the administration," Benjamin Wittes, a friend of Comey's, said in interviews.

Wittes, a senior fellow at the Brookings Institution, the editor-in-chief of the Lawfare blog and a frequent critic of Trump, recalls a lunch he had with Comey in March at which Comey told him he had spent the first two months of Trump's administration trying to preserve distance between the FBI and the White House and educating it on the proper way to interact with the bureau.

Wittes said he never intended to publicly discuss his conversations with Comey. But after The New York Times reported earlier this month that shortly after his inauguration Trump asked Comey for a loyalty pledge, Wittes said he saw Trump's behavior in a "more menacing light" and decided to speak out.

Wittes said that Comey told him that despite Trump's attempts to build a personal relationship, he did not want to be friendly with the president and thought any conversation with him or personal contact was inappropriate.

Their conversation took place after Comey's phone call with the president, Wittes said, and Comey told him that his relationship with the president and the White House staff was now in the right place.

"'I think we've kind of got them trained,'" Wittes said, paraphrasing what Comey told him.

But he said Comey had also described other encounters with the president that had troubled him.

One of those occurred at the White House on Jan. 22, just two days after Trump was sworn in. That day, Trump hosted a ceremony to honor law enforcement officials who had provided security for the inauguration.

Wittes said that Comey told him that he initially did not want to go to the meeting because the FBI director should not have too close a relationship with the White House. But Comey went because he wanted to represent the bureau.

The ceremony occurred in the Blue Room of the White House, where many senior law enforcement officials — including the Secret Service director — had gathered. Comey — who is 6 feet 8 inches tall and was wearing a dark blue suit that day — told Wittes that he tried to blend in with the blue curtains in the back of the room, in the hopes that Trump would not spot him and call him out.

"He thought he had gotten through and not been noticed or singled out and that he was going to get away without an individual interaction," Wittes said Comey told him.

But Trump spotted Comey and called him out.

"Oh and there's Jim," Trump said. "He's become more famous than me."

With an abashed look on his face, Comey walked up to Trump.

"Comey said that as he was walking across the room he was determined that there wasn't going to be a hug," Wittes said. "It was bad enough there was going to be a handshake. And Comey has long arms so Comey said he pre-emptively reached out for a handshake and grabbed the president's hand. But Trump pulled him into an embrace and Comey didn't reciprocate. If you look at the video, it's one person shaking hands and another hugging."

Comey told Wittes of another encounter, on March 1, that also troubled him.

Wittes said that Comey said that he received a call from the White House and was told that "the president needs to talk to you urgently."

"He's about to get on the helicopter, so doesn't get on the helicopter," Wittes said. "And then when the president gets on he just wants to chitchat."

Wittes said that Comey told him that he perceived the call as Trump still "trying to get him on the team and he saw it in light of his refusal to give him his loyalty."

"Trump was still trying to get him on board," Wittes said.

Wittes said that in another conversation he told Comey he was encouraged by the fact that the Senate was likely to confirm Rod J. Rosenstein, a longtime federal prosecutor, as the deputy attorney general.

To Wittes' surprise, Comey did not completely agree with him.

"He said, 'I don't know. I have some concerns. He's good, he's solid but he's also a survivor and you don't survive that long without making some compromises and I'm concerned about that.'"