The fine is the largest penalty handed down to a water utility for an environmental disaster.
The £20m that Thames Water will now have to pay is ten-times higher than the previous record-high fine, handed out to Southern Water for an incident on Margate Beach in Kent in 2012.
The fine amounts to approximately just two weeks profits for the privatised utility, although the size of the fine reflects new sentencing guidelines as previous fines have not been enough to deter the big companies from environmental infringements.
Thames Water admitted 13 breaches of environmental laws over discharges from sewage treatment works in Aylesbury, Didcot, Henley and Little Marlow.
The company had allowed huge amounts of untreated sewage to enter the waterway in Buckinghamshire and Oxfordshire during 2013 and 2014.
Judge Sheridan told Aylesbury Crown Court it was inconceivable that all the individual managers made the same decisions to run pumps at half levels, describing it as "a shocking and disgraceful state of affairs."
"This was a continual failure to report incidents, and a dreadful state of affairs.
"We all have a duty to protect the environment for people who will enjoy it after us, the next generation."
Both animals and people were affected by the sewage leaks, with dead fish and a dead bird found among the untreated sewage.
In the Aylesbury Area, cray fisherman had been put out of business while the leaks took place, and the dragonfly population was said to have decreased dramatically.
Fish stocks had been depleted through poisoning, and it is expected that it will take ten years to reach former levels. The Environment Agency said it was the biggest freshwater pollution case it had ever undertaken.
At the Little Marlow site, a resident described seeing a TEN FOOT geyser of effluent, spraying ten feet into the air.
Judge Sheridan said on the Aylesbury leaks: "Over 94 days sewage was discharged that had not been adequately treated - roughly equating to 2.3 billion liters, or for context, 945 Olympic Sized Swimming pools.
"Thames Water Utility has a history of non compliance from the regulator. There is evidence of deliberate concealments of unlawful incidents.
"Thames Water ignored warnings from their own staff, 1000s of prompts from alarms from the sites to central control, and made regular illegal discharges into our waterways."
He added that the logbook made for "a pathetic state of affairs" as several entries indicated illegal discharges and also that managers had been informed about them, yet no action was taken.
Despite the regularity of infringements, very few incidents were reported to the Environment Agency.
The court also heard that Thames Water had provided "false impressions of performance, and ignored risks identified by employees and others."
Richard Aylard form Thames Water said outside court: 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.
He added that customers would not bear the brunt of this fine, adding: "This fine will be paid in full by shareholders only."
Thames Water also pleaded guilty to a further charge on March 17 over a lesser discharge from an unmanned sewage treatment plant at Arborfield in Berkishire during September 2013.
Judge Sheridan said, "This is a shocking and disgraceful state of affairs. It should not be cheaper to offend than to take appropriate precautions.
"I have to make the fine sufficiently large that Thames Water get the message. One has to get the message across to the shareholders that the environment is to be treasured and protected, and not poisoned."
Thames Water made an operating profit of £724m in 2015-16 and paid out £82m in Dividends.