The whole point of the project was to make Colorado’s water safer.

Instead, while working to clean a mine in the San Juan mountains last Wednesday, workers with the Environmental Protection Agency unintentionally made the problem worse. A plug at the Gold King Mine site failed, the mine’s owners told the Denver Post, releasing 3 million gallons of toxic yellow sludge into Colorado’s waterways. By Sunday night, the plume had reached Farmington, N.M., more than 100 miles to the south.

The sight of the wastewater, long pent up in a mine that hasn’t been operational since 1923, shocked the state and put the EPA in the hot seat. Why was the agency using heavy machinery at a site known to be full of toxins?

The answer, like the wastewater itself, is a part of Colorado’s history.

Burrowed into the state’s craggy mountains are thousands of mines like Gold King, built during the mining bonanza that marked Colorado’s beginnings. Though most of them have been closed for decades, they continue to make their presence known through the acids that slowly leach — and occasionally violently burst — into the water around them.

“The great news is that modern mining does not allow the release of these waters,” Elizabeth Holley, assistant professor of mining engineering at the Colorado School of Mines, told the Denver Post. “The bad news is we owe our statehood to mining prior to any environmental regulations.”

The documented gold discovery in Colorado is attributed to a Georgia prospector named Lewis Ralston, who was part of a wagon train bound for the already famous mines of California. According to lore, members of the train were resting for a day and Ralston, on a whim, decided to dip his gold pan into an unnamed mountain stream. It emerged with $5 worth of gold, a sizable sum for the time.

A fellow traveler noted in a brusque June 22, 1850, diary entry, “Lay bye. Gold found.”

Members of the wagon train lingered only a few days to examine the find, but Ralston would return eight years later with a team of prospectors. Those men soon found rich gold deposits in the mountains nearby, setting off the gold rush that would turn Colorado from an unexplored frontier of Kansas territory into its own booming state. Colorado was admitted to the Union in 1876.

The towering San Juan mountains around Silverton, Colo., were opened to prospectors in 1874. By the 1880s, more than half a dozen mines were operating in the area, including Gold King, most of them run by the Sunnyside Gold Corp.

Rich with veins of silver, gold and other precious metals, the mines drew thousands of people to the area. The nearby towns — Silverton, Telluride, the aptly named Eureka — were built on the estimated $150 million in minerals that were extracted from the mountains. But the wealth came at a cost.

When underground water runs through a mine, it picks up traces of the minerals that are buried there, explains Colorado Public Radio station KUNC. When it mixes with mineral pyrite, it reacts with air to form sulfuric acid and dissolved iron. It also picks up other heavy metals, like copper and lead, as well as any of the chemicals that miners have been using to extract the resources. By the time it trickles out of the mountain and into nearby waterways, it’s an acidic, often-toxic brew.

In mineral-rich mountains like the site of the Gold King mine, this process can happen even before prospectors start digging in. Cement Creek, the waterway that was first flooded with sludge last week, had been declared undrinkable in 1876, before mining in the area became widespread, according to the Denver Post. But drilling into the mountain sped things up quite a bit.

Ginny Brannon, director of the Colorado Division of Reclamation Mining and Safety, told the Denver Post that until 1977, Colorado had few laws requiring mining companies to deal with the wastewater they created.

“Folks could go out and do what they want and walk away from the sites, and this is one of them,” she said.

The Gold King mine hasn’t been operational since 1923, but several other sites in the same network of mines remained open for decades after. For more than 100 years, the mines were the lifeblood of the surrounding community. They provided the bulk of the jobs and one-third of the county’s annual tax revenue, according to the Durango Herald.

Even two major disasters in the 1970s — a breach in a “tailing pond” (the basins that store contaminated water for processing) that sent tons of wastewater into the local watershed and a 1978 lake collapse that flooded the mine with water and a million tons of mud — didn’t dampen support for the operation.

The multimillion-dollar cleanup costs did. In 1991, Sunnyside shut down its last mine in the area. And much of San Juan County was shut down with it.

“We lost half our population,” Beverly Rich, the county treasurer and chairwoman of the San Juan County Historical Society, told Westword magazine in 2005. “We went from about 200 children to 43 kids in our school. We lost one-third of our county tax revenue. We lost a lot of our volunteer firemen — and good-paying jobs. Mining pays well, and tourism jobs don’t quite cut the mustard.”

The effects of more than a century of mining didn’t disappear along with them. They’re easily visible in the histories of local community, which often glorify their mining past. Silverton’s motto, after all, is “The mining town that never quit.”

“Did mining kill people? Of course, it killed people. Driving cars kills people, too. Do you want to get rid of cars?” Historian Duane Smith, a Durango resident and Fort Lewis College professor who has written several books about Silverton, told the Durango Herald in 2013. “Silverton owes its existence to mining, that’s the truth.”

The lingering effects are also noticeable in the area’s waterways, which were suffering even before this latest breach. According to the Herald, three of the four fish species in the Upper Animas water basin (which includes Cement Creek and drains into the Animas River) disappeared between 2005 and 2010. Five years after that, the river was completely devoid of fish.

Insects and bird species have also fared poorly. And tests of the water flowing into Bakers Bridge, about three dozen miles south of Silverton, found that it carried concentrations of zinc toxic to animals. U.S. Geological Survey Scientists told the paper that the area was the largest untreated drainage site in the state.

The Animas River Stakeholders Group that was set up to deal with the issue after the mines were closed, which includes Sunnyside Gold Corp., didn’t have the estimated $12 million to $15 million it would take to treat the contaminated runoff. And for years, Silverton residents resisted EPA involvement out of fear that the “Superfund” label given to the nation’s worst hazardous waste sites would jeopardize the tourism industry — the only source of income that could replace the vanished mines. A few even hoped that the mines would reopen one day.

Meanwhile supporters of EPA intervention accused Sunnyside of stonewalling the cleanup attempt to avoid liability.

The two sides reached an agreement of sorts this year. The mines would not be designated a Superfund site, and the EPA would provide $1.5 billion to plug the problematic Red and Bonita mine, where polluted water drained at a rate of 500 gallons per minute, according to the Durango Herald.

But water has a habit of finding its way downhill, and plugging one mine often means it simply leaks from others, so the agency had to excavate and stabilize the Gold King mine upstream.

That’s what they were up to on Aug. 5, when the loose material holding the mine together finally gave way. The water that had accumulated in the mine’s long-abandoned tunnels went tumbling into Cement Creek.

“It was known that there was a pool of water back in the mine, and EPA had a plan to remove that water and treat it, you know, slowly,” Peter Butler, who serves as a co-coordinator of the stakeholders group, told KUNC. “But things didn’t go quite the way they planned and there was a lot more water in there than they thought, and it just kind of burst out of the mine.”

The EPA has taken a lot of flak for the way it handled the incident — residents weren’t notified for 24 hours after the breach. But agency officials said that the toxic flood just highlights the need to deal with the rest of the state’s 22,000 abandoned mines.

“It’s very unfortunate,” Bruce Stover, the Colorado Department of Mining official in charge of dealing with abandoned mine sites, told the Associated Press. “We’ve been fighting this war for years, and we’ve lost a battle. But we’re going to win the war.”