A divided supreme court said Tuesday that federal law doesn't require that a Native American child be taken away from her adoptive parents and given to her biological father.

The justices' 5-4 decision came in a case about a federal law intended to keep Indian children from being taken from their homes and typically placed with non-Indian adoptive or foster parents. South Carolina courts said the 1978 Indian Child Welfare Act favored the biological father of the girl, named Veronica. But the South Carolina couple who raised her for the first 27 months of her life appealed that decision.

Justice Samuel Alito, writing for the court's majority, said the federal law didn't apply in this case because the biological father never had custody of the child and abandoned her before birth. Alito also said the law doesn't stop non-Native Americans from adopting the child when no other eligible candidates stepped forward.

The law "doesn't apply in cases where the Indian parent never had custody of the Indian child," said Alito, who was joined in his opinion by chief justice John Roberts, and justices Anthony Kennedy, Clarence Thomas and Stephen Breyer.

"The Act would put certain vulnerable children at a great disadvantage solely because an ancestor – even a remote one – was an Indian," Alito said. "A biological Indian father could abandon his child in utero and refuse any support for the birth mother – perhaps contributing to the mother's decision to put the child up for adoption – and then could play his ICWA trump card at the eleventh hour to override the mother's decision and the child's best interest. If this were possible, many prospective adoptive parents would surely pause before adopting any child who might possibly qualify as an Indian under the ICWA."

The court's decision sends the case back to the South Carolina courts.

But justice Sonia Sotomayor dissented and pointed out that the court's ruling doesn't mean Veronica will now go back to her adoptive parents. The law gives tribes and relatives a say in decisions affecting a child, she said.

"The majority does not and cannot foreclose the possibility that on remand, Baby Girl's paternal grandparents or other members of the Cherokee Nation may formally petition for adoption of Baby Girl," she said. "If these parties do so, and if on remand, Birth Father's parental rights are terminated so that an adoption becomes possible, they will then be entitled to consideration under the order of preference established in" federal law.

Her dissent was joined by justices Antonin Scalia, Ruth Bader Ginsburg and Elena Kagan.

Sotomayor said the court's decision turns the law "upside down, reading it from bottom to top in order to reach a conclusion that is manifestly contrary to Congress' express purpose in enacting ICWA: preserving the familial bonds between Indian parents and their children and, more broadly, Indian tribes' relationships with the future citizens who are 'vital to (their) continued existence and integrity.'"

Added Scalia in a separate dissent: "This father wants to raise his daughter, and the statute amply protects his right to do so. There is no reason in law or policy to dilute that protection."

The Obama administration, 18 states, several Indian tribes, current and former members of Congress and children's welfare groups filed briefs in support of the father. The National Council for Adoption and the American Association of Adoption Attorneys were among the groups that filed briefs in support of the South Carolina couple.

Dusten Brown, a member of the Cherokee Nation, invoked the federal law to stop the adoption arranged by the girl's non-Indian mother when she was pregnant and the Charleston, South Carolina-area couple, Matt and Melanie Capobianco. The couple was present at Veronica's birth in Oklahoma. Brown had never met his daughter and, after the mother rebuffed his marriage proposal, played no role during the pregnancy and paid no child support after Veronica was born.

But when Brown found out Veronica was going to be adopted, he objected and said the law favored the girl living with him and growing up learning tribal traditions.

South Carolina courts agreed and Brown took Veronica, now three, back to Oklahoma at the end of 2011, even though she had lived with the Capobiancos for the first 27 months of her life.

Sotomayor said "the anguish this case has caused will only be compounded" by the court's ruling if another change is made in the girl's living arrangements.

"Baby Girl has now resided with her father for 18 months," she said. "However difficult it must have been for her to leave Adoptive Couple's home when she was just over two years old, it will be equally devastating now, if at the age of three and a half, she is again removed from her home and sent to live halfway across the country."