A motion filed Tuesday in California threatens to derail the entire war crimes case against Special Warfare Operator Chief Edward “Eddie” Gallagher.

Drafted by Gallagher’s civilian defense attorney Timothy Parlatore, it paints a portrait of “stonewalling” prosecutors refusing to turn over evidence that could clear the embattled chief and a federal cop who allegedly went rogue by cherry-picking witness statements to salvage a rickety case.

“Rather than conduct a proper investigation in search of the truth, (the agent) began with a pre-determined conclusion and went about finding evidence to support that conclusion, while ignoring or suppressing anything that conflicted with that narrative,” Parlatore wrote in his filing.

Gallagher, 39, is accused of stabbing to death an unarmed and seriously wounded Islamic State prisoner of war during a 2017 deployment to Iraq, plus shooting an old man and a young girl in a violent spree that prosecutors contend might have claimed hundreds of lives.

Although the motion accuses prosecutors of withholding evidence benefiting Gallagher — records independently uncovered by Navy Times — the motion expends much of its ink on the Naval Criminal Investigative Service, an agency Parlatore accuses of botching the entire probe.

And the lead investigator on the case, NCIS Special Agent Joe Warpinski, is in Parlatore’s legal cross hairs.

Warpinski is accused of working “to ensure that witness interviews were documented in a manner that would minimize anything that did not support his pre-determined conclusions," according to the motion.

Mid-2018 interviews with alleged witnesses against Gallagher were videotaped by NCIS agents and turned over to defense attorneys months ago. But no one apparently recorded a round of re-interview sessions in January of 2019.

Instead, NCIS reports about what the witnesses allegedly said appear to have been reconstructed from Warpinski’s notes, which no one on the defense team has seen, according to Parlatore’s motion.

Parlatore’s motion accuses Warpinski of acting like a gatekeeper of exculpatory evidence, excluding witness statements that hurt the case against Gallagher.

To Parlatore, it’s all part of a pattern of conduct he believes calls into question every non-videotaped interrogation NCIS has conducted in the probe.

A list of questions about those bombshell allegations sent to NCIS officials by Navy Times went, for the most part, unanswered.

After citing the NCIS policy of never commenting on ongoing investigations, however, spokesman Adam Stump said all agents “are expected to uphold the highest standards of professional conduct when conducting investigations.”

Navy Times sent a similar request for comment about Parlatore’s motion to the Office of the Judge Advocate General of the Navy, which oversees the service’s prosecutors.

In a written statement emailed to Navy Times, OJAG spokeswoman Patty Babb said her department’s “policy is to not comment on the specifics of ongoing litigation that may prejudice the due administration of military justice.”

Theoretically, Navy Times shouldn’t even have Parlatore’s motion.

During a Friday hearing at Naval Base San Diego, Capt. Aaron Rugh — the military judge hearing the Gallagher case — issued a blanket gag order on all filings in the matter.

But Rugh’s ruling not only sped up the stream of secret records and internal military messages flowing to Navy Times, it indirectly triggered Parlatore’s filing to dismiss the entire case.

It all began last week, when the Navy Times began trying to make sense of a string of email messages exchanged in early April between military prosecutors and Brian Ferguson.

Ferguson is an attorney and Air Force reservist who represents a group of SEAL eyewitnesses who have expressed reluctance in participating in the NCIS investigation and Gallagher’s court-martial trial, which is slated to begin on May 28.

According to the email messages uncovered by Navy Times, a SEAL sniper was forced to conduct a second round of interviews with Warpinski and prosecutors on Jan. 10.

In his message about the interrogation, Ferguson raised red flags about how prosecutors and Warpinski later ended up describing the petty officer’s statements to Gallagher’s defense attorneys.

According to Ferguson’s message, the sniper said he never saw Gallagher shoot an elderly Iraqi man on Father’s Day in 2017, and couldn’t remember other details tied to the alleged war crime.

The petty officer also indicated that his memories about meetings regarding an alleged command cover up of the war crimes were “foggy” and “not very clear” and “a blur," especially discussions about the purported murder of the Islamic State fighter, which he insisted he didn’t witness.

That was interesting to Navy Times because a Jan. 15 write up of the re-interview session by Warpinski stated that the SEAL sniper “knew that” Gallagher had shot him by process of elimination — the elderly victim was in the chief’s “field of fire and nobody else in their tower could have taken that shot.”

When Navy Times tried to talk to Ferguson about the leaked emails and the SEAL sniper’s recollection of events, he gave a firm “no comment.”

Ferguson also refused to talk about a warning typed at the top of that and other messages that referenced Kastigar v. United States.

That’s a landmark 1972 U.S. Supreme Court ruling that found the government can use immunity deals to compel a witness to testify, a powerful tool by federal prosecutors to hurdle the Fifth Amendment right to avoid self-incriminating testimony.

Prosecutors previously had tried — and failed — to prod Rugh to remove Ferguson as the SEAL sniper’s attorney, arguing that he was using him and more than a dozen other holdout witnesses to secure broad immunity deals for the entire group, an allegation the Texas attorney strongly denied.

But a Kastigar assertion also indicated that Ferguson was trying to protect his client from prosecutors in case they tried to use evidence against him derived from a re-interrogation meeting or, potentially, a proffer session.

In proffer sessions, potential witnesses discuss their knowledge about a crime with prosecutors with the assurance that their words won’t be used against them. The rules dictating the meetings often are guided by “queen for a day” letters hashed out between prosecutors and defense attorneys ahead of the sessions.

Navy Times already had a stack of similar documents but a proffer request from Ferguson on behalf of his client wasn’t in it.

If one existed, however, it would have to be supplied to the defense team, so Navy Times contacted Parlatore.

Parlatore not only didn’t know anything about a proffer session, he didn’t realize that Ferguson had raised pointed questions about how NCIS and the prosecution described testimony by that SEAL sniper and other witnesses in reports shipped to the defense team.

Parlatore hung up. But according to another string of emails provided to Navy Times, he apparently got off the phone to immediately contact Gallagher’s prosecutors — Cmdr. Christopher Czaplak and Lt. Brian John from the Navy, and Marine Capt. Conor McMahon.

That sparked another series of email messages from McMahon and Czaplak that didn’t seem to answer Parlatore’s questions.

So the defense attorney reached out to Ferguson, who supplied the emails to him, according to the motion.

On Monday, Czaplak finally sent the same evidence to Parlatore, too.

According to his motion, Parlatore found the messages “illuminating” because they allegedly helped to prove that “stonewalling” prosecutors had made it a habit of turning over “sanitized reports” typed by Warpinski.

And according to Parlatore’s motion, that wasn’t the only problem with Warpinski’s handling of the investigation, which he described as “extraordinarily poor and deeply flawed.”

Parlatore’s motion accused Warpinski of fudging the timeline of the shooting, with Ferguson’s client saying the man might have been shot up to 20 minutes before he saw his body.

Instead of an old man, the alleged victim might’ve been as young as 31 years of age — but more likely in his 40s — and in the field of fire of other snipers, the motion revealed.

And although another SEAL sniper claimed Ferguson’s client told him that Gallagher fired the shot that struck a girl walking along the Tigris River in July of 2017, other evidence seemed to indicate that he never said that at all, and it remains a mystery how the other sniper came to believe the chief gunned her down.

Based on the new evidence, Parlatore’s motion called the two attempted murder charges tied to the old man and the girl “absolutely unsustainable” and urged that they be immediately dismissed or, at least, broken off from the main murder trial.

Reached in Manhattan on Wednesday, Parlatore told Navy Times that Rugh’s gag order prevented him from specifically discussing his allegations, but he urged NCIS and the Pentagon to begin probing the investigators and the prosecution team.

“This investigator is unusually incompetent in this case. Someone should look into his credentials," Parlatore said.

“If they really had good evidence against Gallagher they wouldn’t need to engage in this kind of gamesmanship. There’s no place for this in the criminal justice system, especially when they’re trying to put an innocent man in prison for the rest of his life."

Rugh has yet to issue a ruling on Parlatore’s motion.