WASHINGTON — In what may be its most significant religious liberty decision in two decades, the Supreme Court on Wednesday for the first time recognized a “ministerial exception” to employment discrimination laws, saying that churches and other religious groups must be free to choose and dismiss their leaders without government interference.

“The interest of society in the enforcement of employment discrimination statutes is undoubtedly important,” Chief Justice John G. Roberts Jr. wrote in a decision that was surprising in both its sweep and its unanimity. “But so, too, is the interest of religious groups in choosing who will preach their beliefs, teach their faith and carry out their mission.”

The decision gave only limited guidance about how courts should decide who counts as a minister, saying the court was “reluctant to adopt a rigid formula.” Two concurring opinions offered contrasting proposals.

Whatever its precise scope, the ruling will have concrete consequences for countless people employed by religious groups to perform religious work. In addition to ministers, priests, rabbis and other religious leaders, the decision appears to encompass, for instance, at least those teachers in religious schools with formal religious training who are charged with instructing students about religious matters.