Legality is essential.

But so is humanity.

And while we are a nation of laws, we also should strive to be a nation of compassion — and common sense.

Should the legal system have taken a then-27-month-old girl away from the only parents she had ever known on the final day of 2011?

Not without an extraordinary reason.

Should the legal system correct that injustice by taking her away from the natural father who has been her lawful custodial parent for more than a year?

The circumstances say yes.

Matt and Melanie Capobianco of James Island lost their adoptive daughter Veronica due to a court ruling 12˝ months ago. However, the U.S. Supreme Court recently agreed to hear their appeal of that decision, with oral arguments possibly beginning as soon as April.

Veronica, who turned 3 in September, is now also known as “Little Star” — the Cherokee name she has been given since her biological father Dusten Brown won custody of her and took her to Oklahoma.

Yet as The Post and Courier’s Glenn Smith reported Sunday in a front-page story: “Before Veronica was born in September 2009 in Oklahoma, her biological parents canceled their engagement and went separate ways. Brown, an Army soldier, acknowledged paternity in text messages to the mother, but did not give her financial support.”

And: “The Capobiancos, who had been through seven failed attempts at in vitro fertilization, met Veronica’s mother through an adoption agency, developed a close relationship with her and adopted the baby at birth. The mother is not an American Indian.”

The biological father, though, is an American Indian.

While Mr. Brown initially neglected to be part of his daughter’s life, he filed suit to gain custody of her four months after learning of her adoption, citing the 1978 federal Indian Child Welfare Act.

He won in Charleston County Family Court. He won again when an appeal by the Capobiancos was rejected by the S.C. Supreme Court.

The law upon which his suit is based requires preference for Native American parents in custody disputes.

Thus, Mr. Brown is bound to prevail again in the U.S. Supreme Court, right?

Maybe not. Some legal experts didn’t expect the nation’s highest court to take the case — and regard that acceptance as a warning sign that the outcome is far from assured.

Another reason for the Capobiancos to be optimistic: Many Americans, presumably including some U.S. Supreme Court justices, rightly resist playing race-based favorites.

Though our state Supreme Court did rule against the adoptive parents, it did so by a mere 3-2 margin — and with, as the justices wrote, “a heavy heart.”

Regardless of what the U.S. Supreme Court ultimately decides, or what the rest of us think the verdict should be, this is a heart-wrenching case.

It’s also a sad reminder that bad judgments by adults — in legislative bodies, courts and beyond — often harm innocent children.