Riot police helped a mother regain custody of her 8-year-old daughter on Thursday in a tragic case that has riveted Lithuania for three years and led to three deaths.

Thirty-nine protesters were detained as they tried to prevent the police from carrying out a 5-month-old court order saying the mother should regain custody of her daughter from a house where relatives were keeping her.

Many Lithuanians in the southern town of Garliava violently opposed the order because they allege the girl's mother, Laimute Stankunaite, is part of a pedophile ring.

Protesters had long prevented authorities from taking the girl, Deimante Kedyte, from her deceased father's relatives by forming a cordon around the house. But early Thursday morning Stankunaite and her lawyer — both wearing bulletproof vests and surrounded by dozens of police carrying shields — whisked the girl out of the house to a waiting van.

The demonstrators screamed and shouted obscenities, and many were later shown crying.

Prime Minister Andrius Kubilius defended the action. "People have different opinions about this operation, but Lithuania has its laws, its Constitution, and everybody has to respect it — including law enforcement institutions," he told reporters.

Video and photos of the operation immediately went viral, and several hundred Lithuanians met in downtown Vilnius, the capital, to hold a vigil outside President Dalia Grybauskaite's residence and urge her to reverse the court decision.

"We are here because we care for our country. We see it is being demolished with the help of authorities as they use force against an innocent child and destroy the republic's moral foundations," said vigil participant Darius Kuolys.

It was a dramatic development in a tragic case that has riveted Lithuanian society for the past three years.

In 2009, the girl's father, Drasius Kedys, claimed his daughter was being abused by a pedophile ring involving Stankunaite.

After Kedys failed to get a court order protecting his daughter, he allegedly killed a judge and the mother's sister, both of whom he accused of being part of the pedophile ring.

Kedys then disappeared, only to be found dead near a reservoir in mysterious circumstances two years ago. His funeral was attended by thousands of Lithuanians who had come to regard him as a martyr who dared fight a corrupt justice system.

On Thursday, the girl and her mother were moved to an undisclosed location under constant police protection.