Supreme Court ruled Monday that legislative bodies such as city councils can begin their meetings with prayer, even if it plainly favors a specific religion.

The court ruled 5 to 4 that Christian prayers said before meetings of an Upstate New York town council did not violate the constitutional prohibition against government establishment of religion; the justices cited history and tradition.

“Ceremonial prayer is but a recognition that, since this Nation was founded and until the present day, many Americans deem that their own existence must be understood by precepts far beyond the authority of government,” Justice Anthony M. Kennedy wrote for the court’s conservative majority.

“The prayer opportunity in this case must be evaluated against the backdrop of historical practice,” the majority wrote in its opinion. “As a practice that has long endured, legislative prayer has become part of our heritage and tradition, part of our expressive idiom, similar to the Pledge of Allegiance, inaugural prayer, or the recitation of ‘God save the United States and this honorable Court’ at the opening of this Court’s sessions.”

The majority justices further argued that the intended audience is not “the public, but lawmakers themselves.”

The ruling reflected a Supreme Court that has protected religion and practices in civic life without crossing the line into an endorsement of a particular faith. All nine justices endorsed the concept of legislative prayer, with the four dissenters agreeing that the public forum “need not become a religion-free zone,” in the words of Justice Elena Kagan.

The majority said legislative prayers need not be stripped of references to a specific religion — the prayers at issue often invoked Jesus Christ and the resurrection — and said those given the opportunity to pray before legislative meetings should be “unfettered” by what government officials find appropriate.

“Absent a pattern of prayers that over time denigrate, proselytize, or betray an impermissible government purpose, a challenge based solely on the content of a particular prayer will not likely establish a constitutional violation,” Kennedy wrote.

He was joined by Chief Justice John G. Roberts Jr. and Justices Antonin Scalia, Clarence Thomas and Samuel A. Alito Jr.

Kagan’s dissent noted that the town could have remedied its problems by finding more religiously diverse prayer-givers, she said. The First Amendment’s promise, she wrote, is that “every citizen, irrespective of her religion, owns an equal share in her government.”

Justices Ruth Bader Ginsburg, Stephen G. Breyer and Sonia Sotomayor joined her.

The case involved the New York town of Greece, just outside Rochester, where the council regularly opened its meetings with a prayer delivered by someone from the community. The speakers were recruited from local houses of worship, which were overwhelmingly Christian.

In fact, every meeting from 1999 to 2007 opened with a Christian prayer, and even after two of the town’s residents filed a lawsuit, only a handful of non-Christians have delivered the invocation.