The Cannibal Cop got his first taste of freedom Tuesday after nearly two years in jail — then headed home to sink his teeth into some of his mom’s home cooking.

Gilberto Valle’s mother, who wept as a judge ordered him freed, said she planned to whip up a platter of “pasteles,” Latin American meat pies, once they arrived at her home in Middle Village, Queens.

“I’m going to cook him his favorite meal,” said Elizabeth Valle.

One of Gilberto’s brothers brought milk and beer for the party.

Valle, 30, was freed on $100,000 bond after a surprising ruling that tossed his conviction for scheming to kidnap, kill, cook and eat his then-wife and other women, because a judge believes it was all fantasy.

The disgraced ex-NYPD cop maintains that while he admittedly engaged in depraved online correspondence, he never ­in­tend­ed to carry out the grisly plots.

“I want to take this opportunity to apologize to everyone who has been hurt, shocked or offended by my infantile actions,” Valle said outside Manhattan federal court.

Valle also thanked his family, his public-defender legal team and even the guards and inmates at the federal jail in lower Manhattan, where he’d been locked up since his October 2012 arrest.

Prosecutors plan to appeal, with Assistant US Attorney Hadassa Waxman saying Valle is still a “danger to the community.”

His wife, Kathleen, who went to authorities after seeing the twisted correspondences on his computer in their Forest Hills home and became the prosecution’s star witness, ­declined to comment.

Under terms of his release, Valle must live in his mom’s home and wear an electronic monitoring anklet.

He also is barred from using a computer or the Internet, and must undergo mental-health treatment. He had no such therapy in jail.

In a 118-page ruling late Monday night, Manhattan federal Judge Paul Gardephe overturned the jury verdict that found Valle guilty of kidnapping conspiracy, which carries a maximum life sentence.

­Gardephe said it was “more likely than not the case that all of Valle’s Internet communications about kidnapping are fantasy role-play.”

“Despite the highly disturbing nature of Valle’s deviant and depraved sexual interests, his chats and e-mails about these interests are not sufficient — standing alone — to make out the elements of conspiracy to commit kidnapping,” the judge wrote.

While he conditionally granted Valle a retrial on the kidnapping charge, Gardephe upheld Valle’s misdemeanor conviction for illegally using the NYPD’s database for information on alleged targets.

Valle, who had not yet been sentenced but remained jailed during his appeal, has already spent more than the one-year max behind bars that the misdemeanor conviction carries.

A department source said that because of the computer charge, Valle “will not be coming back to the NYPD.”

Lex Alexander, 36, who lives next door to Valle’s mom, said, “It’s crazy to get convicted for your thoughts. I’m happy for him. But some of the people on the block are going to flip.”

Additional reporting by Linda Massarella, Erin Calabreseand David K. Li