The President replied, according to Comey, that lots of people wanted his job and "he would understand if I wanted to walk away''.
Comey's instincts, he wrote, were that both the setting and the conversation "meant the dinner was, at least in part, an effort to have me ask for my job and create some sort of patronage relationship. That concerned me greatly, given the FBI's traditionally independent status in the executive branch.''
The President then made his demand for loyalty.
"I didn't move, speak, or change my facial expression in any way during the awkward silence that followed,'' Comey wrote. "We simply looked at each other in silence. The conversation then moved on, but he returned to the subject near the end of our dinner.''
When prompted again on the subject of loyalty, Comey said he replied, "You will always get honesty from me''.
Comey said that once before Trump's inauguration, and again at the January dinner, he assured the President that he was not personally under investigation. He also told the President later on that he had shared that information with congressional leaders.
In essence, Comey's written testimony confirms a key claim that Trump has made - that three times, Comey told the President he was not under investigation.
But it also paints a portrait of a strained, awkward relationship between the two men, in which the President frequently expressed his displeasure about the Russia probe in ways that alarmed the FBI director.
The written testimony also recounts a face-to-face conversation the two men had on February 14 - Valentine's Day - at the Oval Office, where many senior officials had gathered for a counterterrorism briefing.
After the meeting, the President asked everyone to leave. Attorney-General Jeff Sessions and senior adviser Jared Kushner lingered in the room, but the President told them to leave, too, according to Comey.
When the door by the grandfather clock closed, Comey wrote, the President said "I want to talk about Mike Flynn'' - the former National Security Adviser who was forced out after disclosures about his conversations with the Russian ambassador to the US, Sergey Kislyak. Flynn had resigned a day earlier.
"I hope you can see your way clear to letting this go, to letting Flynn go. He is a good guy. I hope you can let this go,'' the President said, according to Comey. The FBI Director replied only that "he is a good guy''.
In that conversation, the President repeatedly complained to the FBI Director about leaks, and Comey said he agreed with him about the harm caused by leaks of classified information.
Comey said he understood the President to be asking for him to "drop any investigation of Flynn in connection with false statements about his conversations with the Russian ambassador in December. I did not understand the president to be talking about the broader investigation into Russia or possible links to his campaign''.
The former FBI Director wrote that he found the conversation "very concerning, given the FBI's role as an independent investigative agency.''
Later, Comey complained to Sessions that he should not have been left alone with the president, and Sessions did not reply, according to the written testimony.
Then, in late March, Trump called Comey at the FBI. In that conversation, the President called the Russia probe "a cloud'' hanging over his ability to lead the country.
He also expressed continued frustration that unsubstantiated allegations in a private dossier about him had become public, including lurid claims of sexual activity while in Russia.
"He said he had nothing to do with Russia, had not been involved with hookers in Russia, and had always assumed he had been recorded when in Russia,'' Comey wrote.
"He asked what we could do to 'lift the cloud.' I responded that we were investigating the matter as quickly as we could, and that there would be great benefit, if we didn't find anything, to our having done the work well. He agreed, but then re-emphasised the problems this was causing him,'' Comey wrote.
After that phone call with the President, Comey said he called acting deputy attorney-general Dana Boente to tell him what was discussed, and "await his guidance''. Comey said he never heard back from Boente.
Then, on April 11, Comey wrote, the President called him and asked him what he had done about getting out word that he was not personally under investigation. The President told him "the cloud'' of the probe was interfering with his ability to do his job.
"I have been very loyal to you, very loyal; we had that thing you know,'' Trump told Comey, according to the written testimony. "I did not reply or ask him what he meant by 'that thing.'''
He added: "That was the last time I spoke with President Trump.''
-AP, AAP