The director of public prosecutions in England and Wales, Alison Saunders, is to step down at the end of her five-year contract in October.
While at the Crown Prosecution Service she oversaw the successful prosecution of Stephen Lawrence’s killers.
But recently she has faced criticism after several rape trials collapsed due to evidence not being disclosed.
Ms Saunders told BBC Radio 4’s Today programme the service had improved during her tenure “despite cuts”.
She said it had been her decision to leave the role and that criticism of her work at the CPS (Crown Prosecution Service) was “incredibly inaccurate” and “hugely insulting” to the service’s staff.
The CPS faced criticism when, in December 2017, the trials of Isaac Itiary, who was accused of raping a child, and Liam Allan, both collapsed when new evidence came to light.
Police and prosecutors are expected to disclose evidence that could assist the defence case or undermine the prosecution’s but these cases demonstrated that evidence was not being shared early enough.
It later emerged the number of prosecutions in England and Wales that had collapsed because of a failure to disclose evidence had increased by 70% in the previous two years.
Ms Saunders described issues with the disclosure regime as “extremely regrettable” and said the problems with disclosure were part of a “systemic failing across the justice system” which had been going on “for some years”.
She said the job had been a “tremendous privilege” and she was “proud of everything the service has achieved” over the past five years.
Head of the civil service Sir Jeremy Heywood praised her leadership of the CPS.
Ms Saunders, who will move to multinational law firm Linklaters, had faced calls to resign in June 2015 when her decision not to prosecute Labour peer Lord Janner over claims of historical child sexual abuse was overturned by an independent QC.
The CPS had said there was enough evidence to merit prosecution but that it was not in the public interest to proceed against the former MP.
The ruling reversing that decision made Ms Saunders the first director of public prosecutions to have a major prosecuting decision reviewed and overturned.
A judge later ruled that Lord Janner was unfit to stand trial.
The peer’s son, Daniel Janner – himself a criminal law QC – attacked the way the CPS dealt with his father’s case and said Ms Saunders had been “an appalling DPP” who was “regarded by those in the legal profession as someone who wasn’t up to the job”.
By Clive Coleman, BBC legal correspondent
Alison Saunders was dealt a tough hand as head of the Crown Prosecution Service. The service has sustained major cuts that undoubtedly affected the CPS’s ability to carry out its role.
However, Ms Saunders’ tenure has been dogged by controversies.
They included her being the first DPP to be overruled on a “victim right to review”. She decided it was not in the public interest for the late Labour peer Lord Janner to stand trial for alleged sexual abuse because he was suffering from dementia. An independent QC disagreed.
There was bitter press criticism in the wake of the phone-hacking scandal when journalists were prosecuted for paying public officials for leaked information. Nine cases were dropped as the prosecution was scaled back and no journalist was convicted.
More recently a series of rape trials collapsed where the prosecution failed to disclose critical evidence to the defence. That has led to a review of all rape and serious sexual assault cases, and widespread claims of systemic prosecution failings on disclosure which is a fundamental principle of our fair trial system.
Ms Saunders joined the CPS as a barrister in 1986 rising to become director of public prosecutions in 2013.
It was as chief crown prosecutor for London in 2012 that she oversaw the successful prosecution of two men who killed Mr Lawrence.
The 18-year-old was stabbed to death in an unprovoked and racist attack as he waited at a bus stop in south-east London in 1993.
In the 2013 New Year Honours, she was appointed a Companion of the Order of the Bath for services to law and order for her work particularly after the 2011 London riots.
Announcing she would be stepping down, Attorney General Jeremy Wright thanked her for her service and called her an “accomplished CPS prosecutor whose successful record includes the prosecution of Stephen Lawrence’s killers”.
“I have no doubt that she’ll be greatly missed within the organisation,” he said, adding that recruitment for her successor would begin later this month.