Faith-based adoption agencies that are paid by the state of Michigan will no longer be able to turn away LGBTQ couples or individuals because of religious objections under a legal settlement announced Friday.

The agreement was reached between Democratic Attorney General Dana Nessel's office and lawyers for the American Civil Liberties Union, which sued in 2017 on behalf of two lesbian couples and a woman who was in foster care in her teens.

"Discrimination in the provision of foster care case management and adoption services is illegal, no matter the rationale," Nessel, who pursued settlement talks after taking office in January, said in a statement. "Limiting the opportunity for a child to be adopted or fostered by a loving home not only goes against the state's goal of finding a home for every child, it is a direct violation of the contract every child-placing agency enters into with the state."

Michigan, like most states, contracts with private agencies to place children from troubled homes with new families. The lawsuit alleged that the same-sex couples were turned away by Catholic Charities and Bethany Christian Services because they are gay.

A 2015 Republican-enacted law says child-placement agencies are not required to provide services that conflict with their sincerely held religious beliefs. But the definition of services does not include those provided under a contract with the state Department of Health and Human Services, according to the suit and resulting settlement.

The Becket Fund for Religious Liberty, which intervened in the case on behalf of St. Vincent Catholic Charities and others, accused Nessel and the ACLU of trying to stop the state from working with faith-based adoption agencies.

"The result of that will be tragic," attorney Lori Windham said in a statement. "Thousands of children will be kept from finding the loving homes they deserve. This settlement violates the state law protecting religious adoption agencies."

Two plaintiffs, Kristy and Dana Dumont of Dimondale near Lansing, issued a statement saying they are "so happy" for same-sex couples who are interested in fostering or adopting children.

"We are hopeful that this will mean more families for children, especially those who have been waiting years for a family to adopt them," they said. "And we can't wait to welcome one of those children into our family."

The ACLU has said the suit was filed after the office of former GOP Attorney General Bill Schuette declined to speak to it about possible discrimination. Nessel, who is gay, has criticized the law. As a private attorney, she successfully fought to overturn Michigan's ban on gay marriage.

As of 2015, Catholic Charities and Bethany Christian Services were on average doing 25 to 30 percent of the state's foster care adoptions.

Under the settlement, the state must enforce non-discrimination provisions in its contracts in cases where an agency accepts a referral but refuses to work with LGBTQ people interested in fostering or adopting any of the children it has accepted.

FOLLOW NBC OUT ON TWITTER, FACEBOOK & INSTAGRAM