A Manhattan federal jury on Monday found a former CIA programmer guilty of lying to the FBI and of contempt — but failed to reach a verdict on the far more serious charges that he turned a trove of secret documents from the spy agency over to Wikileaks.

US District Judge Paul Crotty declared a mistrial in the case of accused leaker Joshua Schulte after the jury declared itself “extremely deadlocked” on the eight most serious charges at the trial — including illegal gathering and transmission of national defense information.

Schulte, 31, still faces up to five years on the lesser counts.

Prosecutors accused the onetime programmer of pulling off the largest breach of classified information in the history of the CIA when he allegedly gave hackers access to the agency’s top-secret hacking tools.

At his four-week trial, federal prosecutors portrayed Schulte as a vindictive and disgruntled employee who put US security at risk by leaking information on how the CIA spied on foreign adversaries.

“These leaks were devastating to national security,” Assistant US Attorney Matthew Laroche said during closing arguments last week. “The CIA’s cyber tools were gone in an instant. Intelligence gathering operations around the world stopped immediately.”

“Josh Schulte is no patriot,” Laroche said. “Far from it. He’s vengeful and he’s full of rage.”

Crotty ordered both sides back to court on March 26, when the government could announce a new trial.

Schulte pulled off the breach by swiping backup files from a CIA program called Confluence on April 20, 2016, prosecutors alleged at the trial.

They presented evidence he attempted to cover his tracks in the theft of the files by following instructions published by Wikileaks for sources who pass them classified data. The files Schulte stole appeared on the whistleblowing website more than a year after he stole them.

After his 2017 arrest, Schulte continued his vendetta against the United States from behind bars, using contraband cellphones smuggled into the Metropolitan Correctional Center in Lower Manhattan to attempt to launch an “information war” against the US, prosecutors said in court.

With the smuggled cellphone, Schulte set up a Twitter account he used to publish more classified information and attempted to pass sensitive material to a reporter from the Washington Post.

An inmate at the MCC who helped smuggle the phones into the troubled lockup testified he alerted guards after overhearing Schulte say he planned to solicit help from Russia.

Schulte’s defense attorney argued prosecutors were on a “mission” to secure a conviction against Schulte and scapegoated him in an effort to get to the bottom of an embarrassing leak.

“The CIA joined up with the FBI and started to work on their mission. And they focused, literally, within days, they focused on the one man, Josh Schulte,” Attorney Sabrina Shroff said in her closing argument.

Shroff argued the CIA workers on Schulte’s computer network openly shared passwords and highlighted that a witness from the agency said security in the office had become “woefully lax.”

“It’s like your home. If hundreds of people have a key to your home, if you leave the door open, if you leave your windows open, you always leave your door and your windows open, you leave them unlocked, can’t anyone just come in at any time they want?” Shroff said.

“You wouldn’t know who stole something from your house if you left your house that unlocked. And you know who else doesn’t know? The CIA didn’t know, and they don’t know,” she added.

Schulte’s lawyers had sought a mistrial in the case last month saying prosecutors withheld evidence.

With Post wires