More than 180,000 people in northern California have been told to evacuate after two overflow channels at the US's tallest dam were found to be damaged.
The 770ft (230m) high Oroville Dam is not itself at risk of collapsing, but its emergency spillway was close to caving in, officials said.
Officials feared the damaged spillway could release large amounts of floodwater downstream.
The excess water has now stopped flowing.
However, late on Sunday, Butte County Sheriff Kory Honea said the evacuation orders remained in place.
Water levels in the reservoir have risen following heavy rain and snow after years of severe drought.
It is the first time that Lake Oroville, which lies 65 miles (105km) north of Sacramento, has experienced such an emergency in the dam's near 50-year history.
The evacuation order came after water levels in the reservoir rose sharply last week. The dam's main spillway, also known as an overflow channel, was found to be damaged.
As the water rose even higher, the dam's emergency spillway was activated for the first time since its completion in 1968.
However, this secondary slipway was also found to be damaged.
An evacuation unlike any other
It wasn't just the people who needed to be moved out of harm's way - the emergency has prompted a relocation of fish on a scale never before attempted in a flood situation. Downstream from Oroville Lake, workers have transferred five million baby fish at the state-operated Feather River Hatchery for the endangered Chinook salmon.
Deadly amounts of silt, sand and mud are spewing into the ponds. The hatchery raises about eight million salmon a year, or 30% of the $4bn salmon-fishing industry in the state, said Andrew Hughan, spokesman for California Department of Fish and Wildlife. About three million of those fish are still at risk because of the eroding spillway.
With water visibility at zero, dozens of workers have been scooping up the fish, one net at a time, and moving them by truck to a holding pond. One million steelhead trout eggs have had to be left behind and are unlikely to survive in the turbid water.
In a statement posted on social media on Sunday afternoon, Mr Honea ordered residents to evacuate, repeating three times that it was "NOT a drill".
The California Department of Water Resources warned that the emergency spillway next to the dam was "predicted to fail".
There was gridlock on roads heading out of Oroville, a town of 16,000 people, with some evacuees complaining that they should have been given more warning.
One evacuee, Nancy Borsdorf, told AP she "panicked" and was in such a hurry to leave she "grabbed some wet laundry. Can you believe that?"
Several hours after the evacuation order, the emergency spillway was still standing.
However, California Fire Incident commander Kevin Lawson said officials stood by the decision to evacuate residents, rather than risk thousands of lives.
He said if the situation was not dealt with they were looking at "a 30ft wall of water coming out of the lake".
The California Department of Water Resources said it was releasing as much as 100,000 cubic feet (2,830 cubic metres) of water per second from the main spillway to try to lower the lake's level and relieve the pressure.
Helicopters were dispatched to drop boulders to try to block the eroded area in the spillway.
Butte County's official Twitter feed shared news of emergency shelters, and reported that many hotels were fully booked in the wider area.
One local resident, Javier Santiago, moved his family to the dam's visitor centre, which sits at the top of the structure and away from the flow of water.
"We're going to sleep in the car," he told Reuters news agency, adding that he had packed blankets, pillows and a little food for himself, his wife and their two children.
Gurtej Singh, a manager at a Sikh centre in Sacramento, said the local mayor's office contacted his organisation to ask if they would host evacuees.
"We, in turn, put a call out to members of our community to see if they could provide food, bedding etc, so that around 50 people could stay at our centre," he told the BBC.
Sheriff Honea said that the evacuation was declared to avoid a "worst-case scenario".
He added that no decision had been made as to when people would be allowed back into their homes, as the authorities were still assessing the risks.
Doug Carlson, from the California Department of Water Resources, told the BBC that the situation was looking positive, as the lake level had dropped during the night after the emergency measures were taken.
"That's very good news for the people downstream," he said.
After a long period of drought, California has been experiencing heavy rain and increased snowfall, which has led to flooding and mudslides.
On Friday, California Governor Jerry Brown asked the Federal Emergency Management Agency to declare a major disaster.