A family court judge was wrong to order two boys to be removed from the care of their mother following a hearing in Wiltshire, the Court of Appeal has ruled.
Three appeal judges suggested that Judge Katharine Marshall would have made a different decision had she taken more time to reflect.
The also said Judge Marshall - who made an order after a hearing in a family court in Swindon in June - should have listened to what the boys were saying when she met them.
Appeal judges said the case should be re-considered by a High Court judge.
They said the boys - aged 14 and 12 when taken away - should stay with their mother in the meantime.
The mother, who is separated from the boys' father and re-married, had described the way her sons were taken away as "violent".
One appeal judge, Lord Justice Ryder, said the boys had been removed late at night with police in attendance.
He said the circumstances had been "distressing to all involved" - and the younger boy had wet himself.
Lord Justice Ryder said the older boy had been placed into foster and the younger boy had gone to live with his father.
He said they had been separated from each other for the first time.
Detail of the case emerged in a written appeal court ruling following a hearing in London in July.
The children and their parents were not identified but judges named a local authority involved as Wiltshire Council.
Appeal judges said the boys had been at the centre of family court litigation since their parents separated a decade ago.
They had been living with their mother - and her new husband - and having contact with their father.
A court had ruled that they should spent the summer of 2014 with their father - but after two days they had "absconded" from their father's home.
Judge Marshall had subsequently ordered that they should be removed from their mother's care - and the mother had appealed against that decision.
"No doubt because there was no agreement about how the removal and separation was to occur, a recovery order had to be made," said Lord Justice Ryder.
"The removal happened late at night with the police in attendance.
"The circumstances were distressing to all involved, including at least one professional. (The younger boy) was so distressed that he evacuated his bladder and had to change his clothes.
"The removal was described by mother's representatives as 'violent'."
He said appeal judges had allowed the appeal and set aside Judge Marshall's order - but had done so "without criticism of anyone".
"If there is any lesson to be learned by everyone involved, it is that a judge has to give him or herself time regardless of what anyone else wants that judge to do," said Lord Justice Ryder.
"I would suggest that the decision that was made in this case would not have been made in the way that it was had time been taken to reflect on the history, the implications for the boys, the options available and the patent need for further and better evidence.
"This is one of those family cases that a family court judge instinctively knows will cause harm to the children involved whatever decision is made.
"With that in mind, the analysis that has to be undertaken must bring to bear an acute focus on the balance of welfare factors given the facts of the case."
Lord Justice Ryder said Judge Marshall had "very properly" met the boys - but had said she could not discuss their wishes and feelings with them.
He said it was plain that the boys "could not believe what they were hearing".
And he said Judge Marshall "could and should" have listened.