President Trump’s national security adviser, Michael Flynn, resigned late Monday night amid mounting accusations that he had illicit communications with the Russian ambassador to the United States that positioned him as a potential target for blackmail.

Flynn submitted his letter of resignation to the president just three weeks into the administration, saying he “inadvertently” gave Vice President Mike Pence “incomplete information” on phone calls he had with Russian Ambassador Sergey Kislyak in which he allegedly discussed lifting sanctions against Moscow.

“I have sincerely apologized to the President and the Vice President,” the letter stated, “and they have accepted my apology.”

Flynn, who was fired by then-President Barack Obama as head of the Defense Intelligence Agency, said he was honored to serve with Trump and believed in the mission to “make America great again.”

Retired Army Gen. Keith Kellogg will take over on an interim basis.

The swift resignation came just hours after The Washington Post reported that weeks ago, then-acting Attorney General Sally Yates had warned the White House that Flynn had misled Pence about the nature of his conversations with Kislyak.

Yates told the White House counsel that the Justice Department was concerned Flynn might be vulnerable to blackmail after he insisted to Pence and others that he had not discussed Obama’s sanctions against Russia during a call with Kislyak, the paper reported.

Obama levied the sanctions after it was revealed that Russia was all but certainly involved in hacking and interference in the US presidential election.

Flynn’s contact with the Russian ambassador before Trump was sworn in could violate the Logan Act, which bans unauthorized US citizens from “communicating with a foreign government.”

The national security adviser made conflicting public statements on the communications as more information came to light.

US intelligence agencies regularly monitor calls by Russian diplomats, and reports claim there is a transcript of the Dec. 29 phone call as the sanctions were levied against Vladimir Putin.

Flynn appeared to be in the president’s good graces just hours before his resignation Monday as he sat in the front row of Trump’s news conference with Canadian Prime Minister Justin Trudeau.

Later Monday evening, the White House press secretary, Sean Spicer, said that Trump was “evaluating the situation.”

The New York Times also reported that the US Army has been investigating Flynn’s ties to Russia and whether he was paid by that country during a trip he took to Moscow in 2015.

During an interview with The Washington Post last year, Flynn admitted that he had been paid by the Russian state-run television station RT.

Trump’s 36-year-old son-in-law, Jared Kushner, has been assisting in the search to replace Flynn.

One of the names being considered was disgraced former Gen. David Petraeus, according to Politico.

Petraeus, a former head of the CIA for Obama, was himself caught in a scandal when it was revealed that he had leaked classified information to his mistress and biographer, Paula Broadwell. He resigned in 2012 and served two years’ probation as part of a plea deal.

Other possible picks for the high-level position include: Stephen Hadley, former national security adviser to President George W. Bush; Tom Bossert, who also served as a national security aide under Bush; Adm. James Stavridis; and Department of Homeland Security head John Kelly.