The State of Texas had no right to seize more than 400 children from their families living on the ranch of a polygamous sect, an appeals court ruled on Thursday.

The ruling could unravel one of the most extensive child-custody cases in United States history, which began when officials penetrated the Yearning for Zion Ranch near Eldorado more than six weeks ago.

The Third Court of Appeals in Austin, Tex. said the state did not have sufficient grounds for the "extreme" measure of removing every baby, child and teenager from the compound, run by the Fundamentalist Church of Jesus Christ of Latter-day Saints.

The court said the state did not provide proof the children were in immediate danger, which is the only legal way children in Texas can be taken from their parents without a court order. It also found the state did not show any evidence proving the children were sexually or physically abused.

The children were rounded up in a raid that started on April 3 after a girl called an abuse helpline claiming she lived on the ranch and had been forced into an abusive marriage. Authorities were never able to locate the girl and are investigating whether the call may have been a hoax.

The children are currently living with foster families scattered across the state. It was not clear Thursday whether the ruling meant they would soon be returned to their parents.

One of the children seized was reportedly a teenaged Canadian girl from a polygamous community in Bountiful, B.C. According to The Globe and Mail, two people claiming to be her parents went to Texas shortly after the raid and tried to bring her home.

They told Texas authorities their 17-year-old daughter had just arrived in the state a few weeks earlier on a trip to visit her grandmother. However, a former church member familiar with the Canadian family told The Globe the girl may have been in Texas for up to two years and was likely married to an older church member.

There are numerous ties between the sect members from Yearning for Zion and those in Bountiful. All are break-off members of the Mormon Church, which renounced polygamy more than 100 years ago.

The man who claims to be the Canadian girl's father was part of a crew that built homes for the families inside the Texas compound. Her supposed brothers run a company that builds such homes, the Globe reported.

A Texas court is expected to review the girl's case on June 4, although it is not clear how Thursday's ruling will affect those proceedings.

Child Protective Services took the children on the grounds that the church's members, who believe polygamy brings glorification in the afterlife, pushed the girls into underage sex and marriage. Child services asserted the sect's boys were being raised to become perpetrators of such offences later in life.

"The existence of the FLDS belief system as described by the department's witnesses, by itself, does not put children of FLDS parents in physical danger,'' the court said in its ruling, overturning the order to keep the children by state District Judge Barbara Walther, a former family law lawyer.

The appeals court said the state was wrong to consider all the inhabitants of the ranch as one household, ruling that any claims of abuse could only apply to individual households.

After the raid, many of the women who accompanied the seized children gave several different ages and names for themselves and their children, as well as conflicting information about which children were theirs.

Child protection workers found the children themselves to be little help in clearing up the confusion, as many identified several different women as their mothers and believed all the children living in their home were their siblings.

Members of the Fundamentalist Church of Jesus Christ of Latter-day Saints say they are being persecuted for their religious beliefs.

With files from The Associated Press