Confectionery giant Cadbury has been fined £1m for food and hygiene offences over a salmonella outbreak in which more than 40 people fell ill.
More than one million chocolate bars were recalled
The outbreak at the firm's plant in Herefordshire led to the recall of more than a million bars in the UK.
The Birmingham company admitted nine charges brought by Herefordshire and Birmingham councils.
Birmingham Crown Court was told the outbreak was caused by a leaking pipe at the Marlbrook factory.
The firm was also ordered to pay an additional £152,000 in costs at Monday's hearing.
Birmingham City Council is responsible for enforcing health and safety laws at Cadbury's plant in Bournville.
Separately Herefordshire Council also prosecuted the company over the state of its factory near Leominster where some of the ingredients of the chocolate were processed.
Salmonella was found in some of the firm's products between January and March 2006 and Cadbury's recalled many of its products on 23 June.
A total of 42 people fell ill and three had to receive hospital treatment.
Recorder James Guthrie QC fined Cadbury £500,000 for putting unsafe chocolate on sale and £100,000 on each of two other charges brought by Birmingham City Council.
The judge also fined the firm £50,000 for each of six offences relating to food safety breaches at its factory in Marlbrook, Herefordshire.
At the hearing on Friday the court heard how Cadbury changed its quality-testing systems, allowing salmonella to enter its chocolate bars, to save money.
However, the judge said he did not believe the firm had made the changes in a deliberate cost-cutting attempt.
Recorder Guthrie said: "I regard this as a serious case of negligence.
"It therefore needs to be marked as such to emphasise the responsibility and care which the law requires of a company in Cadbury's position."
Sallie Booth, the solicitor representing 12 people affected by the contaminated chocolate, said: "Our clients are relieved that Cadbury have pleaded guilty to the charges brought against them, and in doing so accept their responsibility to the public.
"The £1m fine sends a clear message that companies who have a great deal of responsibility for protecting public health cannot afford to ignore a potentially dangerous situation and cannot take a risk with the public's health."
A spokesman for Cadbury apologised and offered the company's "sincere regrets" to the people who were taken ill.
He said: "Quality has always been at the heart of our business, but the process we followed in the UK in this instance has been shown to be unacceptable.
"We have apologised for this and do so again today. In particular, we offer our sincere regrets and apologies to anyone who was made ill as a result of this failure.
"We have spent over £20m in changing our procedures to prevent this ever happening again."