The Crown Prosecution Service and Met Police paid a family more than £600,000 in damages and costs after a child witness was identified to a gang.
The 16-year-old boy had been promised anonymity to give evidence about a violent gang attack, but details were inadvertently passed to gang members.
The family of three was moved for its protection. The 2008 payout is thought to be one of the largest of its kind.
Prosecutors said the service's actions "fell below our accepted standard".
The family was threatened after details of the boy's identity were disclosed, and had to be relocated as part of a witness protection scheme, although they were not given new identities.
In a statement, the boy, his mother and her partner told BBC News they had been left with "no option" but to leave their homes, careers, families and friends "without even being able to say goodbye".
They said other children in the family also had to leave.
"The children were uprooted from their schools and whisked away without an opportunity to explain: The trauma and upset this caused is beyond words."
The family's solicitor, Fiona Murphy, told BBC Radio 4's Today programme: "The boy witnessed a violent gang attack and he agreed to provide a statement to the police on the express promise that his identity would not be revealed to the suspects.
"Through a series of individual and systemic failings, his name and address were revealed to the criminal gang and the family began to experience a campaign of harassment and intimidation, and when they brought their concerns to the attention of the Metropolitan Police it was denied that their identity had been revealed."
She said the police had finally advised the family they had to go into witness protection.
The family blamed the mistake on the Crown Prosecution Service and the Metropolitan Police and launched legal action against them for psychiatric damage, lost earnings and disruption to their lives.
The CPS and the Met eventually paid damages of more than £550,000, with the CPS paying almost two-thirds, £350,000.
As part of the settlement, the CPS and the Met also had to pay £50,000 legal costs between them as well as apologise to the family.
The family said that, for the young witness, "no sum of compensation would have given him back his youth".
"He will never recover from this experience, he has lost trust in the police and if he were to witness a similar crime tomorrow - he would simply look away."
Ms Murphy said it was the largest known payment of compensation for a violation of the right to private and family life brought against state agencies.
The case was settled in December 2008 but the details were never made public.
In December 2010, the CPS revealed - following a Freedom of Information Act request by the BBC about civil claims - it had made a payment of £350,000 but refused to provide further information.
The BBC appealed to the Information Commissioner and was told by the CPS in December 2011 that the claim related to a "failed request for anonymity at a trial". No other information was given.
It was only after a further request to senior prosecution officials that the CPS agreed to provide fuller details about the case.
The CPS said: "This payment relates to a case dating from four years ago where information was passed to the defence which led to concerns about the safety of a young witness and their family, so that they had to be provided with protective measures.
"The CPS recognised that its actions in this case fell below our accepted standard and, together with the Metropolitan Police Service, reached an agreed settlement of damages and an apology, with the parties concerned.
"We regret that on this occasion we did not provide the support which is normally available to witnesses."
The Metropolitan Police said it regretted the failings highlighted by the case, and added: "Where we get it wrong we should support those affected and if appropriate provide compensation."
'Criminals in fear'
Offering witnesses support and protection is an "integral" and "vital" part of the justice system, the Met said.
Det Ch Supt Stuart Cundy, head of the Trident gang crime command, that tackles gang-related violence in London, said: "It is important that the police learn from every case to improve our support for witnesses.
"Trident can and does protect witnesses. Success is when communities work with us, putting the criminals not the witness in fear."
Last week, the CPS was criticised over the way it treated young victims and witnesses in a joint inspection report by HM Inspectorate of Constabulary and the Crown Prosecution Service Inspectorate.
Inspectors said young people in England and Wales were being "left to flounder in an imperfect system" and warned that their interests "must be taken seriously".
The report found young people were not consulted on how they were to testify in court and that some cases were delayed or adjourned for several months.