A furious Mayor Bloomberg teed off on a panel of judges who overturned the conviction of a 14-year-old boy caught carrying a loaded handgun during a stop-and-frisk by cops.

“I just think it defies logic,” the mayor told reporters during a Fourth of July parade on Staten Island.

“Here we are getting guns off the streets, and the judges are putting them right back on the streets.”

Bloomberg was referring to the decision Tuesday by a five-judge panel in a Manhattan appeals court to reverse the conviction for the teen.

It came only days after a separate panel of judges threw out a different conviction against a 14-year-old who was found with a loaded pistol and, three months later, shot and nearly killed a Queens man.