Former FBI Deputy Director Andrew McCabe filed a lawsuit Thursday against the Department of Justice and his ex-employer arguing he was wrongly fired from the agency because he was not sufficiently loyal to President Donald Trump.

McCabe was fired from the FBI in March 2018 after then-Attorney General Jeff Sessions accepted an internal FBI recommendation that he be terminated. McCabe's termination occurred less than two days before he was to retire and become eligible for full pension benefits. The timing of his termination effectively deprived him of his ability to retire with a full pension.

McCabe, a target of relentless attacks from Trump, had taken the reins of the agency in 2017 during the turbulent days after the abrupt firing of FBI Director James Comey. He had stepped down from the FBI in January 2018, but had remained on the federal payroll and been planning to retire.

In his suit — filed Thursday in federal court in Washington — McCabe alleged that his firing was the product of “Trump’s unconstitutional plan and scheme to discredit and remove DOJ and FBI employees who were deemed to be his partisan opponents because they were not politically loyal to him.”

The lawsuit lists as defendants Attorney General William Barr, the Justice Department, FBI Director Christopher Wray and the FBI, although it says Trump was ultimately responsible for the decision to have McCabe fired.

“Trump, acting in an official capacity as President of the United States, is responsible and accountable for Defendants’ actions," McCabe said in the suit. "Trump purposefully and intentionally caused the unlawful actions of Defendants and other Executive Branch subordinates that led to Plaintiff’s demotion and purported termination.”

McCabe said in the lawsuit that Trump demanded his "personal allegiance" and “sought retaliation” when McCabe “refused to give it." He added that "Sessions, Wray, and others served as Trump’s personal enforcers rather than the nation’s highest law enforcement officials, catering to Trump’s unlawful whims instead of honoring their oaths to uphold the Constitution.”

The White House, the Department of Justice and the FBI all declined to comment on the lawsuit.

McCabe opened a counterintelligence investigation into Trump after Comey was fired and has repeatedly said the president's attacks on him were designed to discredit him, as well as the former special counsel's investigation into Russian interference in the 2016 election and possible obstruction of justice by Trump.

In the lawsuit, McCabe said he “would have otherwise been permitted to retire as he had long planned,” if it “were not for Trump’s plan and scheme and the complicity of Defendants and other Executive Branch subordinates.” McCabe is seeking that his termination be voided and he be allowed to retire in good standing with his full pension and other benefits.

He is also seeking an order preventing the listed defendants “from interfering” with his receipt of the pension and benefits and “from taking any further retaliatory actions.”

McCabe's termination was recommended by the agency he served for 21 years. The FBI's Office of Professional Responsibility proposed the termination based on the findings of the Justice Department's inspector general, which was examining the bureau's handling of the Hillary Clinton email investigation.

As part of the inquiry, McCabe was questioned about conversations FBI officials had with a reporter in October 2016 regarding the FBI's investigation of the Clinton Foundation. The inspector general's report concluded that McCabe was not completely candid in answering questions about those conversations, NBC News reported in March 2018, a finding that McCabe has disputed.