(CNN) -- The Supreme Court has ruled against a Christian campus group that sued after a California law school denied it official recognition because the student organization limits its core membership to those who share its beliefs on faith and marriage.
At issue was the conflict between a public university's anti-discrimination policies and a private group's freedom of religion and association.
The 5-4 ruling was written by Justice Ruth Bader Ginsburg, who was on the bench a day after her husband passed away.
The law school, wrote Ginsburg, "caught in the crossfire between a group's desire to exclude and students' demand for equal access, may reasonably draw a line in the sand permitting all organizations to express what they wish but no group to discriminate in membership."
In dissent, Justice Samuel Alito wrote, "I do not think it is an exaggeration to say that today's decision is a serious setback for freedom of expression in this country." He was supported by Chief Justice John Roberts, and Justices Antonin Scalia and Clarence Thomas.
Justice Anthony Kennedy was the swing vote in this contentious case.
The Christian Legal Society -- which has chapters around the country -- had sought official recognition from the University of California's law school in San Francisco. The 30-member group is still in existence, even after its application was rejected five years ago.
Any student may attend the group's meetings, but voting members and officers must affirm a "statement of faith," that includes the belief "Christians should not engage in sexual conduct outside of marriage between a man and a woman," according to the society's website.
The school says that leads to discrimination which, under law, it cannot sanction.
The court drew sharp lines over how far both the school and the student group must go to claim "institutional autonomy" in their respective policies, and to satisfy conflicting First Amendment claims of free speech and association.
Lawyers for the group say members should have the discretion to hold their own views and ensure their campus leaders share similar religious ideas.
They told the court that the school, Hastings College of the Law, had singled them out for rejection, while recognizing other groups that limit membership to those of shared beliefs.
But the school cited its policy as the main reason for turning down the group's application, saying it should be open to all. The school said the "statement of faith" would essentially keep gays and lesbians from joining.
Groups given official endorsement by the University of California can receive school funding, office space and the freedom to recruit on campus, but may not reject anyone because of sexual orientation, religious beliefs, or other criteria protected under federal and state law.
The case could have broader applications for so-called "charitable choice" programs, where religion-based groups provide social services, often with federal funding. Such a group's tax exemptions and hiring practices could be affected by how the justices apply the law in this school dispute.
A federal appeals court in San Francisco last year ruled against the student group. But a similar lawsuit against Southern Illinois University two years ago was successful, and the Christian Legal Society received official recognition there.
The case was Christian Legal Society Chapter of the University of California, Hastings College of the Law v. Martinez (08-1371).