Thames Water has been fined a record £20m after pumping 1.9 billion litres of untreated sewage into the River Thames.
The company admitted water pollution and other offences at sewage facilities in Buckinghamshire and Oxfordshire.
Fish and birds died following the spills in 2013 and 2014.
The £20.3m fine is the largest penalty handed down to a water utility for an environmental disaster.
Judge Francis Sheridan said the scale of the problem was such that it must have been known up the chain of command.
He told Aylesbury Crown Court it was inconceivable that all the individual managers made the same decisions to run pumps at half levels, calling it a "shocking and disgraceful state of affairs".
He added: "It should not be cheaper to offend than to take appropriate precautions."
The spills occurred at four Thames Water Utilities Ltd sewage treatment works, at Aylesbury, Didcot, Henley and Little Marlow, as well as a large sewage pumping system in Littlemore in Oxford.
Hundreds of fish were killed and sewage spilled into nature reserves, while nappies and other debris went into the Thames and the adjoining River Thame.
Manholes also overflowed and fewer dragonflies were reported.
Environmental damage was caused in the riverside towns of Henley and Marlow.
Company director Richard Aylard said: "We have failed in our responsibility to the environment and that hurts both personally and professionally, because we do care.
"We've also failed in our responsibility to our customers who pay us to provide an essential public service all the time, every day and not just some of the time, and we apologise for all of those failings."
Judge Sheridan said the company had a "history of non-compliance" and that managers had ignored warnings and "risks identified by employees and others".
Staff recorded a "failure waiting to happen", he said.
Robert Davis, from the Environment Agency, called it some of the worst pollution he had witnessed.
He added: "I couldn't believe what I was seeing. The river was visibly polluted bank to bank with sewage.
"It was grey, it was lifeless, it had fish floating along it, and was polluted as far as the eye can see both downstream and upstream. It was really sad to see such a beautiful river so badly polluted."
Farmer Michael Woodford built a 3km [1.9 mile] fence to make sure his cattle did not access the water at the time.
He said: "We were very concerned about the welfare of our cattle.
"This type of pollution is very harmful to livestock and could be fatal to animals.
"It was shocking because the river was a haven of wildlife. There were always fish and crayfish in there. The whole of the wildlife was being destroyed by all this pollution."
Chief executive of Thames Water Steve Robertson said he deeply regretted the spills but claimed things at the company had improved since it had increased staff in key roles.
"We understand our huge responsibilities to the environment, have learned from these serious events and continue to invest at the rate of around £20m a week on continually improving our service to our customers and the environment."
The company has 21 days to pay the fine.
The previous largest fine handed down by a court was £2m, given to Southern Water in December after sewage was discharged into the sea near Margate.
Anne Brosnan, chief prosecutor for the Environment Agency, said: "Thames Water was completely negligent to the environmental dangers created by the parlous state of its works.
"Our investigation revealed that we were dealing with a pattern of unprecedented pollution incidents which could have been avoided if Thames Water had been open and frank with the Environment Agency as required by water company industry protocol."
Jeremy Stern, BBC News, at Aylesbury Crown Court
This is by far the largest fine Thames Water, or any UK water company, has ever been landed with.
However, the record sentence is not a surprise.
Fines for these types of offences have been going up since new guidelines were introduced in England and Wales in 2014.
Also Judge Francis Sheridan said more than once during this case that he wanted to send a message to shareholders that pollution on this scale is not acceptable.
However, the fine amounts to a tiny proportion of the company's annual income. Thames Water makes an operating profit of around £2m every day.
Louise Bowe, River Thame Conservation Trust chief executive, said: "We have been shocked as the catalogue of events from 2013 have come out in court.
"It was much worse than we thought and explains how the devastating damage to the river came about.
"Poor quality sewage effluent being released reduces oxygen in the water. Fish and other aquatic wildlife struggle to survive and the whole ecosystem can be damaged for many years.
"Some large fish that were killed cannot be replaced as species like large mature chub and roach are simply not available."
Doug Kennedy, from Cuddington, set up the Save the River Thame project after being "appalled" by the spills.
He said: "I was very shocked to find large dead fish on the river. The river was black. It had rather horrid little black flies bouncing over it. You couldn't see into it, it was just horrible.
"It's absolutely disgusting what was going on [at the sewage treatment works]… but we weren't aware of it.
"[There was] floating disgusting material - raw sewage - on the River Thames, as well as on the Thame."
Rose O'Neil, water policy manager at the WWF, said it was "not an isolated issue".
She added: "There are around 15,000 sewer overflows across England releasing raw sewage into our rivers.
"This case highlights the need for water companies to invest in solutions that manage the whole local catchment area such as green infrastructure and sustainable drainage systems. They simply can't continue treating our rivers as their dumping ground."