Idaho's ban on spying at farms, dairies and slaughterhouses violated free speech rights, a federal appeals court ruled Thursday.

"The panel held that the subsection criminalized innocent behavior, was staggeringly overbroad, and that the purpose of the statute was, in large part, targeted at speech and investigative journalists," wrote U.S. Circuit Judge M. Margaret McKeown in a 56-page ruling.

Idaho lawmakers in 2014 passed the law making it a crime to surreptitiously videotape agriculture operations after the state's $2.5 billion dairy industry complained that videos of cows being abused at a dairy two years earlier unfairly hurt their businesses.

The measure passed easily in Idaho, where agriculture is not only one of the leading businesses but also the occupation of many state lawmakers.

Animal rights activists, civil rights groups and media organizations quickly sued once the bill received the governor's signature, arguing the law criminalized a long tradition of undercover journalism and would require people who expose wrongdoing to pay restitution to the businesses they target.

In Thursday's decision, the appeals panel upheld a prior federal judge's ruling that the ban was an unconstitutional infringement of the First Amendment of the U.S. Constitution safeguarding free speech.

The panel also ruled the law correctly criminalized those who made false statements to either obtain records at an agricultural facility or to obtain employment with the intent to inflict harm.

"We are sensitive to journalists' constitutional right to investigate and publish exposes on the agricultural industry. Matters related to food safety and animal cruelty are of significant public importance," McKeown wrote.

"However, the First Amendment right to gather news within legal bounds does not exempt journalists from laws of general applicability."

The panel then reiterated a federal judge's point that there are already state and federal laws on the books that protect private property.

The Idaho attorney general's office was reviewing the decision and planned on discussing it with state officials, said spokesman Scott Graff.

According to the opinion, the panel particularly took exception to the law's ban on audiovisual recordings but not photography, rejecting the state's argument that the act of making a video or audio recording is not protected by the First Amendment.

"Without some legitimate explanation, we are left to conclude that Idaho is singling out for suppression one mode of speech — audio and video recordings of agricultural operations — to keep controversy and suspect practices out of the public eye," the opinion stated.

The Idaho Dairymen's Association — a trade organization that represents Idaho's dairy industry — wrote the measure after the Los Angeles-based animal rights group Mercy For Animals released videos that showed workers at Bettencourt Dairy beating and stomping cows in 2012.

At the time, one legislator supportive of the bill dubbed animal rights groups as terrorists while another described videos depicting animal abuse were used to publicly crucify a company and as a blackmail tool.

A separate lawmaker noted that if the Mercy For Animals video had never been published, the bill wouldn't have surfaced.

Seven states have similar measures — Kansas, North Dakota, Montana, Iowa, Utah, Missouri and North Carolina. Legal challenges are pending in Utah and North Carolina.