Sewage has finally stopped pouring into the Firth of Forth two-and-a-half days after a pumping station failure.
Officials have issued a hygiene warning to beach users
Scottish Water said the discharge was halted by emergency pumps that had been installed at the Seafield plant in Leith over the weekend.
The temporary pumps will remain in place until a full repair of the fault is carried out, officials said.
Scottish Water has apologised for the "catastrophic failure" that allowed millions of litres of sewage to escape.
As much as 100 million litres of partially diluted sewage, enough to fill 170 Olympic-sized swimming pools, may have been discharged after the pump failure on Friday afternoon.
The Seafield plant is in Leith, Edinburgh.
The sewage had been pumping into the Forth at the rate of up to 1,000 litres a second.
The plant, run by Thames Water, treats sewage for 800,000 people in and around Edinburgh.
The failure led to a row over the risk to public health after people were warned to avoid contact with water and stay away from the shoreline.
Many residents have complained they were not informed quickly enough that beaches might be contaminated.
Scotland's First Minister Jack McConnell has called for a full investigation.
Helen Lennox, Scottish Water's head of corporate affairs, apologised to customers for the inconvenience caused.
She said: "This was a catastrophic failure at a pumping station and we have been working around the clock to fix it.
"On investigation our engineers found the repair was a much larger operation than first anticipated and we have had to locate specialist pumps from other parts of the UK".
Stephen Walker, head of environmental health at Edinburgh City Council, urged anyone who came into contact with water from the Forth to follow basic hygiene guidelines.
The Scottish Environment Protection Agency (Sepa) has already said emergency measures to "minimise the risk of pollution" were being put in place and has warned the public not to come into contact with the water.
The failure affected one of the flows going into the treatment works while the rest of the Seafield plant continued to treat the rest of its intake as normal.
Residents in Leith have long campaigned about the smell from the plant.
Rob Kirkwood, the chairman of Leith Links Residents' Association, said: "It has an infrastructure that is basically Third World technology."
John Rae, general manager of customer operations for Scottish Water, said the repair operation had been a complicated one for Thames Water.
He rejected claims by some residents that the station was antiquated.
He said: "The pumping station certainly does not have 'Third World technology'. That is completely erroneous.
"I realise there have been some difficulties but it has been a difficult repair for Thames.
"I would like to apologise on behalf of Scottish Water to our customers that this event has occurred. The main issue for me is to understand what has happened."
Gordon Greenhill, head of community safety at Edinburgh council, said the sewage spill raised public health concerns but added it would not be a long-term environmental problem.
People using the waterfront have been urged to take precautions
"The volume of sewage going into the Forth estuary is a concern as it has the capacity to come back on to the shore," he said.
"Any raw sewage has human pathogens in it which has the capacity to make people ill."
Resident Robbie Lawson said he had not been warned about the sewage when he had been sailing in a dinghy on the Forth on Saturday afternoon.
Mr Lawson said: "There were a lot of us using the water and we were blissfully unaware of any problem until hearing the news headlines later on Saturday."
Meanwhile, Mr McConnell said it was essential that there was an "immediate investigation into the mechanical failure that has apparently caused this spillage and what action needs to be taken as soon as possible to ensure that such a mechanical failure does not occur again".
The SNP and the Scottish Greens questioned the viability of the private finance initiative scheme that was used to install and manage the treatment facilities at Seafield.
Conservative Deputy Leader Murdo Fraser called the incident a "catastrophe" for the local environment.