WASHINGTON — The Supreme Court on Wednesday barred teachers who work at church-run schools from filing discrimination lawsuits against their employers, ruling that the Constitution’s protection for religious liberty exempts church schools from state and federal anti-discrimination laws.

The justices, by a 7-2 vote, shielded two Catholic elementary schools in Los Angeles County from discrimination claims by two teachers who complained they were unjustly fired, one due to an illness and the other due to age.

The court found that since such schools are part of a church’s religious mission, the government may not interfere with decisions about hiring, supervision and firing of teachers.

The decision effectively closes the courthouse door to tens of thousands of teachers nationwide in religious and parochial schools who encounter workplace discrimination based on their race, gender, age, disability or sexual orientation that would otherwise be impermissible.

It is also written broadly enough that it could include many other types of workers at the schools, such as counselors, nurses, coaches and office workers.

In the past, the Supreme Court has recognized an implied “ministerial exemption” that shields churches, synagogues or other religious bodies from being sued by priests, pastors and other ministers. The issue in the pair of cases from Southern California was whether that exemption extended more broadly to teachers in a church-run school whose primary duty was not necessarily religious instruction.

“The 1st Amendment protects the right of religious institutions to decide for themselves, free from state interference, matters of church government as well as those of faith and doctrine,” Justice Samuel A. Alito Jr. wrote for the majority in Our Lady of Guadalupe School vs. Morrissey-Berru.

“The religious education and formation of students is the very reason for the existence of most private religious schools, and therefore the selection and supervision of the teachers upon whom the schools rely to do this work lie at the core of their mission,” he continued.

“Judicial review of the way in which religious schools discharge those responsibilities would undermine the independence of religious institutions in a way that the 1st Amendment does not tolerate.”

Justices Ruth Bader Ginsburg and Sonia Sotomayor dissented.

Kristen Biel was a fifth-grade teacher at St. James Catholic School in Torrance whose teaching contract was canceled shortly after she told the principal she had been diagnosed with breast cancer. She later sued under the Americans with Disabilities Act, which protects employees from discrimination based solely on a disease like cancer. She died last year, but her husband, Darryl Biel, maintained the suit.

Agnes Morrissey-Berru had taught fifth grade at Our Lady of Guadalupe in Hermosa Beach for decades when the principal suggested she might want to retire. She refused, and her teaching contract was not renewed. She then sued, alleging age discrimination.

Lawyers for the Catholic Archdiocese said the suits should be dismissed, citing the ministerial exception recognized by the high court. Also in 2012, the Supreme Court threw out a discrimination suit by a “called teacher” at a Lutheran school in Michigan, whose job included leading worship services.

Citing that precedent, two federal judges in Los Angeles ruled that the Southern California suits by the two former teachers should be dismissed. The 9th Circuit Court disagreed, however, and cleared both suits to proceed, ruling that neither teacher was a religious leader at school.

Sotomayor, in her dissent to Wednesday’s ruling, called the court’s decision “simplistic” because it allows a church to decide which of its employees are central to its religious mission and therefore not covered by anti-discrimination laws.

“Even if the teachers were not Catholic, and even if they were forbidden to participate in the church’s sacramental worship, they would nonetheless be ‘ministers’ of the Catholic faith simply because of their supervisory role over students in a religious school. That stretches the law and logic past their breaking points,” she said.

“The court’s conclusion portends grave consequences. Thousands of Catholic teachers may lose employment-law protections because of today’s outcome. Other sources tally over a hundred thousand secular teachers whose rights are at risk. And that says nothing of the rights of countless coaches, camp counselors, nurses, social-service workers, in-house lawyers, media-relations personnel, and many others who work for religious institutions. All these employees could be subject to discrimination for reasons completely irrelevant to their employers’ religious tenets.”

Darryl Biel said he was disappointed by the court’s opinion. “The court overstated Kristen’s religious duties, which were limited to a couple hours per week. Alito’s opinion did not characterize what Kristen did at that school,” he said. “I am also disappointed in St. James, the Archdiocese, and Trump and his administration for supporting blatant discrimination against women and those with health disabilities.”

It was the third major win for a religious liberty claim in a week.

In a Montana case, the justices ruled that parents who send their children to church-run schools have a right to the same state subsidies or tuition grants afforded to other private schools. There, the court said the Constitution required equal treatment for religion, overriding state constitutions that barred any taxpayer money from going to religious institutions.

And also Wednesday, the justices agreed with the Trump administration and Catholic charities that employers with religious or moral objections to birth control have a right to be exempted from the part of Obamacare that requires them to provide contraceptives to their female employees.

In the case involving Catholic school teachers, the court rejected the notion of equal treatment for religion — central to the Montana decision — when it came to churches as employers. Instead, religious employers were given a special shield from federal discrimination laws.

The Archdiocese of Los Angeles welcomed the ruling. “Religious schools play an integral role in passing the faith to the next generation of believers,” said Adrian Alarcon, spokesperson for Los Angeles Catholic Schools. “We are grateful that the Supreme Court recognized faith groups must be free to make their own decisions about who should be entrusted with these essential duties.”

“Today is a huge win for religious schools of all faith traditions,” said Eric Rassbach, a lawyer for the Becket Fund, who argued the case. “The last thing government officials should do is decide who is authorized to teach Catholicism to Catholics or Judaism to Jews.”

Rachel Laser, president of the Americans United for Separation of Church and State, said the decision “demonstrates how the Supreme Court continues to redefine religious freedom — twisting what is meant to be a shield that protects us into a sword to harm others. The court elevates a distorted notion of religious freedom over fundamental civil rights.”