WASHINGTON — Only seven days after Donald J. Trump was sworn in as president, James B. Comey has told associates, the F.B.I. director was summoned to the White House for a one-on-one dinner with the new commander in chief.

The conversation that night in January, Mr. Comey now believes, was a harbinger of his downfall this week as head of the F.B.I., according to two people who have heard his account of the dinner.

As they ate, the president and Mr. Comey made small talk about the election and the crowd sizes at Mr. Trump’s rallies. The president then turned the conversation to whether Mr. Comey would pledge his loyalty to him.

Mr. Comey declined to make that pledge. Instead, Mr. Comey has recounted to others, he told Mr. Trump that he would always be honest with him, but that he was not “reliable” in the conventional political sense.

The White House says this account is not correct. And Mr. Trump, in an interview on Thursday with NBC, described a far different dinner conversation with Mr. Comey in which the director asked to have the meeting and the question of loyalty never came up. It was not clear whether he was talking about the same meal, but they are believed to have had only one dinner together.

By Mr. Comey’s account, his answer to Mr. Trump’s initial question apparently did not satisfy the president, the associates said. Later in the dinner, Mr. Trump again said to Mr. Comey that he needed his loyalty.

Mr. Comey again replied that he would give him “honesty” and did not pledge his loyalty, according to the account of the conversation.

But Mr. Trump pressed him on whether it would be “honest loyalty.”

“You will have that,” Mr. Comey told his associates he responded.

Throughout his career, Mr. Trump has made loyalty from the people who work for him a key priority, often discharging employees he considers insufficiently reliable.

Video

The New York Times reporters Peter Baker, Maggie Haberman and Matthew Rosenberg analyze the firing of the F.B.I. director, James B. Comey.Published OnMay 11, 2017

As described by the two people, the dinner offers a window into Mr. Trump’s approach to the presidency, through Mr. Comey’s eyes. A businessman and reality television star who never served in public office, Mr. Trump may not have understood that by tradition, F.B.I. directors are not supposed to be political loyalists, which is why Congress in the 1970s passed a law giving them 10-year terms to make them independent of the president.

Mr. Comey described details of his refusal to pledge his loyalty to Mr. Trump to several people close to him on the condition that they not discuss it publicly while he was F.B.I. director. But now that Mr. Comey has been fired, they felt free to discuss it on the condition of anonymity.

A White House spokeswoman on Thursday disputed the description of the dinner by Mr. Comey’s associates.

“We don’t believe this to be an accurate account,” said Sarah Huckabee Sanders, the deputy press secretary. “The integrity of our law enforcement agencies and their leadership is of the utmost importance to President Trump. He would never even suggest the expectation of personal loyalty, only loyalty to our country and its great people.”

At the dinner described by Mr. Trump in his interview with NBC, the conversation with Mr. Comey was quite different. Mr. Trump told NBC that Mr. Comey requested it to ask to keep his job. Mr. Trump said he asked the F.B.I. director if he was under investigation, a question that legal experts called highly unusual if not improper. In Mr. Trump’s telling, Mr. Comey reassured him that he was not.

Mr. Trump did not say whether he asked Mr. Comey for his loyalty. Asked at Wednesday’s White House news briefing whether loyalty was a factor in picking a new F.B.I. director, Ms. Sanders said Mr. Trump wanted someone who is “loyal to the justice system.”

Video

President Trump told NBC’s Lester Holt that the F.B.I. was in turmoil, and that he was going to fire its director, James B. Comey, regardless of any recommendation.Published OnMay 11, 2017CreditCreditDoug Mills/The New York Times

The dinner described by Mr. Comey’s associates came in the early days of Mr. Trump’s administration, as the F.B.I. was investigating Russian meddling in the election and possible ties to Mr. Trump’s campaign. That investigation has since gained momentum as investigators have developed new evidence and leads.

Mr. Trump had met Mr. Comey for the first time in January, during the transition, when, along with the intelligence chiefs, the F.B.I. director presented him with evidence of that intervention. Mr. Comey was tasked by his fellow intelligence directors to also pull Mr. Trump aside and inform him about a secret dossier suggesting that Russia might have collected compromising information about him.

The dinner at which the conversation Mr. Comey related took place was on Jan. 27, almost a month later. CNN reported on Thursday that Mr. Comey never gave Mr. Trump an assurance of his loyalty.

Mr. Comey’s associates said that the new president requested the dinner he described, and said that he was wary about attending because he did not want to appear too chummy with Mr. Trump, especially amid the Russia investigation. But Mr. Comey went because he did not believe he could turn down a meeting with the new president.

During the meal, according to the account of the two associates, Mr. Comey tried to explain to Mr. Trump how he saw his role as F.B.I. director. Mr. Comey told Mr. Trump that the country would be best served by an independent F.B.I. and Justice Department.

In announcing Mr. Comey’s dismissal on Tuesday, the White House released documents from the attorney general and the deputy attorney general that outlined why Mr. Comey should be fired.

Mr. Trump said in the NBC interview, “Regardless of recommendation, I was going to fire Comey.”

“In fact, when I decided to just do it, I said to myself, I said, you know, this Russia thing with Trump and Russia is a made-up story,” Mr. Trump said.

A version of this article appears in print on , on Page A1 of the New York edition with the headline: In a Private Dinner, Trump Demanded Loyalty. Comey Demurred.. Order Reprints | Today’s Paper | Subscribe