The U.S. Supreme Court on Monday ruled in favor of a Missouri church that sued the state after being denied taxpayer funds for a playground project because of a provision that prohibits state funding for religious entities.

The ruling was 7-2.

The case, one of the most closely watched of the term, pitted two parts of the First Amendment against one another – freedom of religion and separation of church and state.

The dispute involved Trinity Lutheran Church in Columbia, Mo., and the state of Missouri.

In 2012, the state launched an initiative to encourage schools to use recycled tires to produce softer playground surfaces. Trinity, which runs a preschool, was denied a state grant to participate in the program -- and lawyers for Trinity argued the state discriminated against the school based on religion.

Chief Justice John Roberts agreed.

“The exclusion of Trinity Lutheran from a public benefit for which it is otherwise qualified, solely because it is a church, is odious to our Constitution all the same, and cannot stand,” Roberts wrote.

During oral arguments in April, Justice Elana Kagan also questioned the church's exclusion.

"You're denying one set of actors from competing [for the grant money] because of religion," Kagan said. She called it a "clear burden on a constitutional right."

Justice Sonia Sotomayor issued a strong dissent – and said Monday’s decision “profoundly changes” the relationship between church and state.

Sotomayor, who read a portion of her dissent from the bench, said the ruling “slights both our precedents and our history, and its reasoning weakens this country’s longstanding commitment to a separation of church and state beneficial to both.”

The state program gives grants to nonprofits seeking a safer recreational environment for children. But Missouri's law at the time -- similar to those in roughly three-dozen other states – prohibited direct government aid to educational institutions that have a religious affiliation.

James Layton, Missouri’s former solicitor general, said Trinity Lutheran "remains free, without any public subsidy, to worship, teach, pray, and practice any other aspect of its faith however it wishes. The state merely declines to offer financial support."

He argued that while the Constitution prevents the government from discriminating against religion, “it does not guarantee churches opportunities for public financing.”

Since then, Republican Gov. Eric Greitens has changed the state policy to allow religious institutions to participate in the program but Monday’s opinion could have an impact on other cases.

The Supreme Court accepted the church's petition for review back in January 2016, when Justice Antonin Scalia was still the senior conservative. His death a month later kept the case on hold, possibly because the eight justices believed they would ultimately tie.

Maureen Ferguson, senior policy advisor with The Catholic Association, called the ruling “a significant victory for fairness and government neutrality towards religious institutions.”

“The Supreme Court is sharply signaling in this decision that the government must stop its growing hostility towards religion and religious institutions, and that antiquated and anti-Catholic Blaine Amendments should not be used as a weapon to discriminate against people of faith.”

Fox News' Bill Mears contributed to this report.