WASHINGTON (AP) — Lawyers for President Donald Trump unleashed a blistering attack on former FBI Director James Comey in a confidential memo last year to the special counsel, casting him as "Machiavellian," dishonest and "unbounded by law and regulation" as they sought to undermine the credibility of a law enforcement leader they see as a critical witness against the president.

The letter, obtained by The Associated Press, provides a window into the formation of a legal strategy currently used by Trump's lawyers as they seek to pit the president's word against that of the former FBI director. Comey's firing in May 2017 helped set in motion the appointment of special counsel Robert Mueller, and one-on-one conversations with Trump that Comey documented in a series of memos helped form the basis of Mueller's inquiry into whether the president obstructed justice.

Mueller is looking broadly into Russia's meddling in the U.S. election and its contacts with people in Trump's campaign.

The June 27, 2017, letter was written by Marc Kasowitz, then the president's lead lawyer, as Mueller and his team were in the early stages of their investigation into Trump associates and as they had begun examining whether the president, by firing Comey, had sought to stymie an FBI investigation into the Trump campaign's ties to Russia. The White House initially pointed as justification for the firing to a Justice Department memo that faulted Comey for his handling of the Hillary Clinton email investigation, though Trump later said that "this Russia thing" was on his mind when he made the move.

The document also could have new relevance in the aftermath of a Justice Department inspector general report that criticized Comey for departing from established protocol in the Clinton investigation.

It's not clear to what extent, if any, the attacks on Comey have resonated with Mueller's team, which continues to seek an interview with the president on whether he had a corrupt intent when he fired the FBI director. And even in the face of withering criticism, Comey has been largely consistent in his telling of his interactions with Trump in his memos, his book and numerous press interviews he's given in recent months.

The 13-page document aims to identify for Mueller what the lawyers believe are grievous errors both in how Comey handled the Clinton investigation and in his early, and limited, encounters with the president. In it, Kasowitz argues that Comey cannot be trusted as a witness because he repeatedly embellished his testimony before Congress, put his "own personal interests and emotions" above FBI protocol and left a cloud of undue suspicion above the president's head.

"Over the last year, Mr. Comey has engaged in a pattern of calculated unilateral action unbounded by governing law, regulation and practice, and plainly motivated by personal and political self-interest," wrote Kasowitz, who has since stepped aside as lead lawyer.

Lawyers for Comey declined to comment Saturday. Kasowitz and Trump lawyer Jay Sekulow did not immediately return messages, and former Trump attorney John Dowd declined to comment.

The document does not focus on questions of Trump's guilt or innocence. Instead, it casts in a negative light actions that Comey has said he carefully reasoned and that he has vigorously defended in his book and interviews. Those include the decision to announce on his own without Justice Department consultation the conclusion of the Clinton investigation, and the decision months later to brief Trump — then the president-elect — on allegations about him in a salacious dossier.

"Mr. Comey continued his Machiavellian behavior after President Trump was elected," Kasowitz wrote.

Among the principal lines of attack are Comey's acknowledgment that he provided his lawyers with contemporaneous memos about his interactions with Trump and authorized one of them to share details with the news media. In one such encounter, Comey said the president asked him at a private dinner for his loyalty and that Comey offered him "honest loyalty" instead.

"There is no 'honest loyalty' in an FBI Director surreptitiously leaking to civilians his privileged and confidential conversations with the president, or misappropriating and disseminating his confidential FBI memos or their contents about those meetings," Kasowitz wrote. "There is no 'honest loyalty' in using those civilians as surrogates to feed stolen information and memos to the press to achieve a personal, political, and retributive objective of harming a sitting president."

Like Trump, the lawyer also complains about Comey's refusal to state publicly to Congress that the president was not under investigation even though he said so privately.

"Despite his repeated assurances to the President over the prior three months that he was not under investigation, the President's repeated pleas to make that fact public, and Mr. Comey's testimony that he had DOJ (Department of Justice) approval to make this 'extraordinary' announcement, Mr. Comey not only declined to clarify that there was no investigation of the President, but he used broad language that only reinforced the inaccurate perception that the President was under investigation," Kasowitz wrote.

The New York Times earlier reported that Kasowitz had written two letters to Mueller in June 2017 and published one in which he categorically rejected the idea that Comey's firing could constitute obstruction of justice. The AP obtained a copy of the other document, in addition to a two-page memo from September in which Trump lawyers lament to Deputy Attorney General Rod Rosenstein that Mueller was "inexplicably" not investigating Comey's "misconduct" they had earlier raised.

Kasowitz says Comey stonewalled the president's request to clear his name in order to "sustain an investigative cloud" over his head that would make it hard for Trump to fire him. Comey, for his part, has said he had already told congressional leaders who was and was not under investigation, and that he was reluctant to make public statements in case something changed and he needed to correct the record.

The letter castigates Comey for usurping the authority of his Justice Department bosses by announcing the conclusion of the Clinton investigation without seeking their approval, a criticism echoed by the inspector general last month. Comey has said he made the announcement alone because of concern that Justice Department leadership was seen as politically compromised.

The letter says Comey "confronted" the president-elect in a January 2017 Trump Tower meeting "with phony but highly embarrassing allegations concerning his personal life" from a dossier compiled by a former British spy.

It was the first in a series of conversations that Comey documented in writing, something Trump lawyers say he did with the ultimate goal of harming the president. Comey has said he told Trump about the dossier allegations because they were widely known in Washington, including by the media, and that he kept his memos because he was concerned that Trump might lie about their conversations.

In the September memo obtained by AP, Dowd, who left the legal team in March, expressed dismay to Rosenstein that there's no grand jury investigation into "the obviously corrupt conclusion" of the Clinton investigation, suggesting it was improper that Comey had begun drafting a statement closing the probe even before Clinton was interviewed.

"Today, you are faced with a terrible blight on our Department of Justice which must be addressed to restore and inspire confidence in the Department," Dowd said in calling for the grand jury investigation.