A Manhattan federal appeals court Thursday affirmed a trial judge’s decision overturning the conviction of so-called “cannibal cop” Gilberto Valle for conspiring to kidnap and eat women, concluding that federal prosecutors, the FBI and a jury had mistaken twisted fantasies for reality.

Valle was convicted on the basis of a series of sexually charged chats with other fetishists over the Internet discussing in great detail plans to abduct, abuse and kill actual women he was friendly with, but his defense team contended he was engaged in “fantasy role play” and never took steps to carry out a plot.

“We are loathe to give the government power to punish us for our thoughts and not our actions,” wrote 2nd U.S. Circuit Court of Appeals Judge Barrington Parker. “That includes the power to criminalize an individual’s expression of sexual fantasies, no matter how perverse or disturbing.”

“Fantasizing about committing a crime, even a crime of violence against a real person whom you know, is not a crime,” Parker concluded in a 2-1 majority opinion that also spanked Manhattan U.S. Attorney Preet Bharara’s office for pressing arguments that were “untethered to reason or common sense.”

The court affirmed a decision by U.S. District Judge Paul Gardephe, who overturned a jury’s 2013 conviction of Valle because of lack of evidence. Gardephe had allowed Valle’s conviction for misusing a police database to research the women to stand, but the 2nd Circuit said what he did was not a federal crime.

The ruling means that Valle, 31, of Queens — a six-year NYPD veteran at the time of the charges who said he aspired to become a lawyer when he was freed last July after Gardephe’s ruling — spent 21 months in prison but committed no crime in the eyes of the law, and is now free with no probation or other legal restrictions.

advertisement | advertise on newsday

A spokesman for Bharara, who issued statements to the media at the time Valle was charged and convicted, said the office had no comment on the court’s findings, or on whether prosecutors would seek further review.

Valle, in a statement sent out by his lawyers, said, “This ruling is a very important victory not just for Mr. Valle, who has now been cleared of all criminal charges, but for an open society that treasures freedom of thought and expression.”

Parker, in a 38-page decision, said the ruling did not mean that “fantasies are harmless,” noting that “fantasies of violence against women are both a symptom of and a contributor to a culture of exploitation, a massive social harm that demeans women.”

But, he said, “We must not forget that in a free and functioning society, not every harm is meant to be addressed with the federal criminal law.”

Like Gardephe, Parker said the charges against Valle made little sense because allegedly serious chats were indistinguishable from dozens of other chats the government conceded were fantasy, and Valle never followed through, at one point discussing in separate chats abductions in Pakistan, Ohio and New York at the same time.

Get the Newsday Now newsletter!

The best of Newsday every day in your inbox.

The judge dismissed the government’s claim it could tell fantasies from real plots, noting, “We do not believe the prosecution satisfies the proof beyond a reasonable doubt standard by relying upon a distinction that is untethered to reason or common sense.”

Parker was joined in his opinion by 2nd Circuit Judge Susan Carney, but Judge Chester Straub dissented, arguing that conspiracies don’t have to be carried out to be a crime, and the court should have deferred to the jury, which had sufficient basis to find at least one plot was real.

“This is not a case about governmental intrusion on one’s personal inclinations and fantasies nor is it a case about governmental punishment of one’s thoughts,” Straub wrote. “It is instead a jury’s determination of guilt for a conspiracy based on definitive conduct. ”