The man accused of gunning down a Mafia kingpin on Staten Island wasn’t intending to kill a mob boss that day, his lawyer says.

In his eyes, Anthony Comello was taking out “a prominent member of the deep state” — whom he allegedly tried to “arrest” at first.

“He ardently believed that Francesco Cali, a boss in the Gambino crime family, was a prominent member of the deep state, and, accordingly, an appropriate target for a citizen’s arrest,” said Comello’s attorney, Robert C. Gottlieb, in court documents filed Friday.

“Mr. Comello became certain that he was enjoying the protection of President Trump himself, and that he had the president’s full support,” Gottlieb added, according to the New York Times.

The 24-year-old had been convinced that Cali was connected to the infamous QAnon conspiracy, which claims there’s a political “deep state” secretly running the country from within the government, among other things.

“Mr. Comello’s support for ‘QAnon’ went beyond mere participation in a radical political organization,” his lawyer said. “It evolved into a delusional obsession.”

Gottlieb intends to argue in court that Comello’s delusions about the QAnon conspiracy drove him to commit murder — and that they are enough to prove he is not guilty by reason of insanity. He’s seeking to have Comello placed in psychiatric care rather than prison.

According to Gottlieb, the young man’s obsession with the “deep state” and other QAnon conspiracies — like the belief that certain Democratic politicians are secretly pedophiles — led to him making multiple “arrest” attempts earlier this year.

In February, Comello allegedly tried to take Mayor Bill de Blasio into custody on two separate occasions, one of which involved him showing up at Gracie Mansion.

He then attempted to place two California Democrats under arrest — Reps. Maxine Waters and Adam Schiff — and even tried getting the US Marshals Service to help. But they reportedly denied his request.

The incidents were later confirmed by law enforcement officials.

Over the years, Comello made “thousands and thousands” of posts, messages and forum comments about the QAnon conspiracies, which Gottlieb plans to use in court as evidence.

“Patriot sleeper cells are awake,” he wrote on one occasion.

Gottlieb said Comello believed that Cali, a member of the Gambino crime family, had been connected to the deep state after seeing a post online that suggested Mafia figures were also part of the conspiracy.

He is accused of killing the mob boss on March 13 outside his Todt Hill home. The slaying was believed to be “premeditated” — with prosecutors charging Comello with second-degree murder.

“The defendant fired 12 bullets, striking him 11 times,” said Staten Island Assistant District Attorney Carrie Low at Comello’s bail hearing. “He drove by the victim’s house several times hours before the attack.”

During his first court appearance in March, Comello showed up with his palm covered in drawings of symbols and phrases tied to QAnon. Low described him at the time as a member of the “far-right organization.”

“He believes that only their laws are the laws he and the rest of this country should follow,” she said.

Comello is due back in court on Aug. 13.