An evangelical Christian fostering agency does not have to work with non-evangelical Christian carers, the High Court has ruled.
Cornerstone (North East) Adoption and Fostering Service went to court after it came under pressure from government regulator Ofsted to abandon its religious ethos.
It followed an inspection by Ofsted last year in which Cornerstone was downgraded from "good" in all areas to "requires improvement".
The inspection report alleged that in recruiting only evangelical Christian carers, Cornerstone was guilty of unlawful discrimination.
Ofsted also said it was discriminatory for Cornerstone to require its carers to abide by its code of conduct on living consistently with the charity's Christian beliefs about marriage between a man and a woman.
High Court Justice Julian Knowles ruled that Cornerstone's recruitment policy was not unlawful, although he determined that the adoption agency cannot compel carers to live by its beliefs on sexual conduct.
"Cornerstone is permitted to exclusively recruit evangelical Christian carers because of the exemption in  to Sch 23 to the [Equality Act] 2010 for religious organisations," his judgement said.
"Cornerstone's recruitment policy does not violate Article 14 of the Convention read with Article 8, as given effect by s 6 of the [Human Rights Act] 1998, insofar as it requires carer applicants to be evangelical Christians."
The judge further ruled that an exception in the Equality Act 2010 allowing religious organisations to limit services on the grounds of sexual orientation does not apply to Cornerstone because it recruits carers on behalf of or under contract with local authorities.
Cornerstone has not yet decided whether to appeal this point of the ruling.
Cornerstone's chairwoman, Reverend Sheila Bamber, said: "The judgment justifies our decision to pursue this legal action. Our right to support Christian families in providing the best possible outcomes for vulnerable children and young people has been upheld.
"But I am saddened that the fundamental place of biblically based Christian marriage in our beliefs has not been recognised. We will carefully and prayerfully consider how to continue our vocation and work to create forever families."
Cornerstone has been supported in its legal action by The Christian Institute. Its Deputy Director for Public Affairs Simon Calvert said: "Ofsted has failed in its attempt to turn a small, much-loved Christian agency into another outpost of its 'muscular liberalism' worldview. Shockingly, it even argued in court that fostering was "a secular act" and that there is no demand for evangelical carers.
"There are 305 other Independent Fostering Agencies in England. Cornerstone is the only one with an evangelical Christian ethos. It achieves excellent results for children and families. And now with this ruling the Court has put beyond doubt that it can continue to recruit only evangelical Christian carers.
"Ofsted tried to use human rights legislation to fatally undermine essential religious exceptions in the Equality Act 2010. But those exceptions were passed precisely to protect the ethos of faith-based agencies like Cornerstone.
"Cornerstone's challenge should help protect churches and other religious bodies that rely for their existence on the protections afforded by the Equality Act."
He said, however, that the judge was "mistaken" in ruling that Cornerstone recruits carers on behalf of local authorities and is therefore not covered by the equality law exception.
"Cornerstone is a private organisation and places children with those within its existing pool of carers. It does not recruit carers on behalf of local authorities," he said.
"This part of the judgment suggests the court failed to recognise that Christian belief informs and shapes every area of life – including sexual ethics and behaviour.
"A decision on whether to appeal will be taken in the coming weeks."