A CIA technician believed to be behind one of the worst leaks in CIA history appeared in Manhattan federal court Thursday armed with a 137-page, handwritten document that proclaimed his innocence and demanded that he be sprung from prison.

Despite being represented by a lawyer, Joshua Adam Schulte made the judge aware of the document, which claims his remand was “unlawful, unconstitutional, and improper,” by blurting out about it in open court.

“I just have a motion I’d like to submit before questions, if that’s OK?” Schulte said at the start of his hearing.

A court officer took the document from Schulte, 29, and handed it to the puzzled judge, who remarked, while flipping through it, that it was hand-written.

“The typewriter is broken” at the Metropolitan Correction Center, Schulte explained.

The ex-CIA software engineer has been in MCC since last year after the feds raided his NYC apartment on suspicion that he had leaked classified documents to WikiLeaks.

He was only charged with kiddie porn at the time and it took until earlier this month for the feds to slap Schulte with a 13-count superseding indictment, which accuses him of leaking classified information, including national defense information, that he believed could be used “to the injury of the United States and the advantage of a foreign nation.”

He faces up to 135 years in prison if convicted.

After Thursday’s hearing, Schulte’s hand-written document was posted to the public docket before being removed moments later — but not before copies had been downloaded.

“It’s only a matter of time, but rest assured, I will prove my innocence,” Schulte wrote, according to a copy of the document obtained by The Post.

“Here, once again, the FBI, with reckless disregard for the truth and no oversight or accountability, have wrongfully attacked an American patriot who has served this country for years and even prevented terrorist attacks in this great city,” Schulte said.

Also on Thursday, Schulte — who appeared at the hearing sporting a neck tattoo with three faded red lines — waived his right to change venue and agreed to be tried in Manhattan.