Rebecca Grace Chittum, one of two little girls switched at birth four years ago, will stay here in the small town where she has been raised, except for weekend visits once a month and a summertime stretch with her biological mother, Paula Johnson, a juvenile court judge ordered today.

The decision ends the drive for custody Johnson launched earlier this year, after relations broke down between her and the grandparents raising Rebecca.

In a still-mysterious mix-up at the University of Virginia Medical Center in the summer of 1995, Johnson's newborn was mistakenly given to Kevin Chittum and Whitney Rogers, whose baby went to Johnson. Chittum and Rogers were killed in a car accident on July 4, 1998, shortly before the baby switch came to light.

Moments after today's decision, people who had been adversaries vowed to work together in Rebecca's best interests. Johnson and several of the grandparents gathered in the middle of courtroom, hugging each other and sobbing.

"I just wanted to be a part of her life," Johnson said as she hugged Whitney's mother, Linda Rogers. Rogers, also weeping, said, "I know you did."

The ruling, after a day and a half of testimony, was a victory for the Buena Vista grandparents, and not atypical in a local court, say psychologists and lawyers familiar with child-custody cases. Lower court judges usually try to keep children in familiar settings. Higher courts, however, often reverse such decisions, returning custody to biological parents, with sometimes wrenching consequences.

In the so-called Baby Richard case, lower courts rejected a Chicago father's custody claim after his girlfriend put their baby up for adoption. On appeal, the state's highest court overturned those rulings, forcing the adoptive parents to give the child, then 4, to his father.

While Johnson's lawyers had vowed earlier this week to take the case to the U.S. Supreme Court if necessary, there was no talk of an appeal today, and both sides said they hoped to avoid more time in court.

Judge John B. Curry II based his decision largely on the comments of a Staunton child psychologist, who testified for about an hour in a rare open session today that taking 4-year-old Rebecca away from her grandparents could be a devastating blow to a little girl who has already lost too much.

Virginia law requires that judges presume a child will be better off with the biological mother. But it allows a judge to keep a child and a mother separated if the mother is unfit or has given up the child voluntarily, or under special circumstances.

Psychologist Nadia B. Kuley said during the brief open session that Rebecca should stay where she was raised and should slowly develop a relationship with her biological mother during brief visits.

Kuley said giving Rebecca to Johnson -- and taking her away from the only family she knows -- could threaten the girl's psychological health, which was shaken by the accident that killed Kevin Chittum and Whitney Rogers. Kuley examined Rebecca three times for a total of about five hours during the past month, she said.

"Rebecca Chittum has already experienced some very traumatic loss," Kuley said. Removing her from her grandparents "would only increase the sense of loss to her."

Kuley said Rebecca seemed very attached to the two sets of grandparents who have been raising her since the deaths of Chittum and Rogers, but seemed ambivalent about Johnson.

When Kuley showed her a picture of Johnson, "She looked at the picture," Kuley told the court. "I said, `Tell me who this is.' She turned around and walked away. She really wanted to stop."

Kuley recommended occasional visits between Johnson and Rebecca, preferably chaperoned by someone in Buena Vista with whom Rebecca has bonded. She also suggested that the visits increase in length only after further psychological evaluations.

For the moment, the cooperation that briefly existed between the families of the two children after the switch was revealed a year ago seems to have returned. The judge acknowledged that bad blood and bitter feelings have developed during the past several months, but he urged the adults to work toward a better relationship for Rebecca's sake.

"This case, there have been extraordinary circumstances," said Curry. "I hope things work out for this child."

Estrangement between the families began because Rebecca's grandparents in Buena Vista had been terrified that Johnson would kidnap her, taking the little girl away from the town of 6,400 forever, according to Rogers.

"I said to myself, `I have lost my daughter, I cannot lose this child too,' " Rogers said. "I was terrified. I knew that she could take something away from me that I loved so much. We panicked."

That panic, she said, caused the Buena Vista families to deny Johnson visits with Rebecca for more than six months. This afternoon, the separation ended when the families gathered with Rebecca at the Pizza Hut restaurant a few blocks from the courthouse.

Rebecca, dressed in a black-and-white-checked party dress with ribbons in her braided hair, sat across from Johnson while more than a dozen family members shared pizza and laughter, conversing without lawyers for the first time in months.

On Thursday, Johnson's lawyers called 11 witnesses to testify that Rebecca would be better off with Johnson. Today, attorneys for the grandparents were prepared with 24 witnesses to attack Johnson as an unfit mother.

It never got that far. Attorneys for the grandparents called only one witness, the child psychologist, before the judge made his ruling.

"It's what we hoped for when we came in, to keep custody here," said Michael Groot, lawyer for one set of grandparents.

Johnson's attorneys said they, too, were pleased.

"It's wonderful that we're not going to be at each other's throats," said attorney Kenneth Mergenthal. "They now seem to be able to work together. This is going to be in the best interests of the child."

There may still be a battle over the other child involved in the switch, Callie Marie Conley, who is being raised by Johnson in her Stafford County home. Both Johnson and one set of grandparents have filed to adopt her. Callie has the last name of Johnson's former boyfriend.

Several lawsuits are pending in the case, including Johnson's $31 million suit against the hospital and her $36 million suit against the maker of the identification bands that mothers and babies wear during their hospital stays.

Investigations have failed to determine what happened at the hospital in July 1995, but the state health department has been critical of sloppy procedures involving the use of the ID bands.

Staff writer Tamara Jones contributed to this report.