MIAMI — A federal appeals court ruled on Thursday that Florida doctors can talk to patients about gun safety, declaring a law aimed at restricting such discussions a violation of the First Amendment's right to free speech.

The 11th U.S. Circuit Court of Appeals found that the law does not trespass on patients' Second Amendment rights to own guns and noted a patient who doesn't want to be questioned about that can easily find another doctor.

"The Second Amendment right to own and possess firearms does not preclude questions about, commentary on, or criticism for the exercise of that right," wrote Circuit Judge Adalberto Jordan in one of two majority opinions covering 90 pages. "There is no actual conflict between the First Amendment rights of doctors and medical professionals and the Second Amendment rights of patients."

Circuit Judge William Pryor, who was a finalist in President Donald Trump's search for a Supreme Court nominee, said in a separate concurring opinion that the First Amendment must protect all points of view.

"The promise of free speech is that even when one holds an unpopular point of view, the state cannot stifle it," he wrote. "The price Americans pay for this freedom is that the rule remains unchanged regardless of who is in the majority."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Related: Florida Man Charged With Trying to Blow Up Target Stores to Tank Company’s Stock

The law was passed in 2011 and signed by Republican Gov. Rick Scott with strong support from the National Rifle Association. It was the only one of its kind in the nation, although similar laws have been considered in other states.

Supporters in the Republican-controlled Florida Legislature insisted it was necessary because doctors were overstepping their bounds and pushing an anti-gun, anti-Second Amendment agenda.

The law was challenged almost immediately by thousands of physicians, medical organizations and other groups such as the American Civil Liberties Union as a violation of free speech in what became known as the "Docs v. Glocks" case. A legal battle has raged in the courts since then, with several conflicting opinions issued.

"We are thrilled that the court has finally put to bed the nonsensical and dangerous idea that a doctor speaking with a patient about gun safety somehow threatens the right to own a gun," said Howard Simon, executive director of the ACLU of Florida.

The 11th Circuit noted that Florida lawmakers appeared to base the law on "six anecdotes" about physicians' discussions of guns in their examination rooms and little other concrete evidence that there is an actual problem. And doctors who violated the law could face professional discipline, a fine or possibly loss of their medical licenses.

"There was no evidence whatsoever before the Florida Legislature that any doctors or medical professionals have taken away patients' firearms or otherwise infringed on patients' Second Amendment rights," Jordan wrote for the court.

Related: Congress Blocks Rule Barring Mentally Impaired From Purchasing Guns

The NRA and Florida attorneys had argued that under the law doctors could ask about firearms if the questions were relevant to a patient's health or safety, or someone else's safety, and that the law was aimed at eliminating harassment of gun owners. But the 11th Circuit said there was no evidence of harassment or improper disclosure of gun ownership in health records, as law supporters also claimed.

"There is nothing in the record suggesting that patients who are bothered or offended by such questions are psychologically unable to choose another medical provider, just as they are permitted to do if their doctor asks too many questions about private matters like sexual activity, alcohol consumption, or drug use," the court ruled.

The ruling did determine that some parts of the law could remain on the books, such as provisions allowing patients to decline to answer questions about guns and prohibiting health insurance companies from denying coverage or increasing premiums for people who lawfully own guns.

The case will return to U.S. District Judge Marcia Cooke in Miami for a ruling that follows the 11th Circuit's direction. The case could, however, also be appealed to the U.S. Supreme Court.