(Reuters) - A federal appeals court on Monday declared a Florida county’s ban on atheists and other non-religious groups from giving invocations before public meetings unconstitutional, even as it ordered the narrowing of an injunction against the practice.

The 11th U.S. Circuit Court of Appeals said Brevard County violated the First Amendment’s “Establishment Clause” by allowing clerics from Christian, Jewish, Muslim and other monotheistic religions and denominations deliver invocations at county commissioner meetings, while excluding atheists, secular humanists and others deemed outside the “mainstream.”

“Brevard County’s haphazard selection process categorically excludes certain faiths - some monotheistic and apparently all polytheistic ones - based on their belief systems,” Circuit Judge Stanley Marcus wrote for a three-judge panel.

Citing U.S. Supreme Court precedents, Marcus said the law was clear that sectarian prayer was allowed, but Brevard County’s practice “is unconstitutional and must be rejected.”

Marcus singled out county officials who testified they would bar prayers from deists, Wiccans, Rastafarians and polytheists, and would have to think “long and hard” before inviting Hindus, Sikhs or followers of Native-American religions.

Brevard County is located in the middle of Florida’s east coast. The appeals court heard the case in Miami.

Lawyers for the county did not immediately respond to requests for comment.

The lawsuit had been filed in 2015 by the Central Florida Freethought Community, the Humanist Community of the Space Coast, the Space Coast Freethought Association and five members of at least one of these groups.

“We’re pleased,” the plaintiffs’ lawyer Alex Luchenitser, from Americans United for Separation of Church and State, said in an interview. “People’s religious beliefs should never determine whether they can participate in civic affairs.”

Monday’s decision upheld a September 2017 ruling by U.S. District Judge John Antoon, but said his injunction “goes too far” by directing Brevard County to give the eight plaintiffs opportunities to offer invocations.

It upheld Antoon’s injunction against the country’s speaker selection practices, and returned the case to him.

The case is Williamson et al v Brevard County, 11th U.S. Circuit Court of Appeals, No. 17-15769.

(Story corrects spelling of lawyer’s last name to “Luchenitser” from “Luchenister” in ninth paragraph.)