This story was originally published by Slate and appears here as part of the Climate Desk collaboration

On Monday, federal courts dealt major setbacks to the controversial Dakota Access and Keystone XL pipelines. The two decisions came directly on the heels of an announcement that energy utilities were abandoning another high-profile project: the Atlantic Coast Pipeline, which would have crossed beneath the Appalachian Trail.

Together, these developments amount to a stunning victory for environmental advocates and tribes who have long challenged these projects in court, and are just the latest roadblocks to the Trump Administration’s “energy dominance” agenda, which has sought to expedite fossil fuel projects in an era of climate change. But, how, exactly did this all come to pass, and back-to-back-to-back at that?

The reason the pipelines have faltered is mainly due to legal errors and injudicious project approvals. It’s a bureaucratic failure rather than any kind of policy directive.

The Dakota Access pipeline is a prime example of how rushing through legal requirements has backfired for federal agencies during the Trump Administration. Following the Administration’s efforts to expedite the permit process, the pipeline was completed in 2017, but legal challenges plagued the project even after oil began flowing.

Led by the Standing Rock Sioux, advocates mounted a successful challenge under the National Environmental Policy Act (NEPA), which requires that all projects with federal approvals take a “hard look” at environmental effects before a project is completed.

In March, a federal district court ruled that the Trump Administration had not adequately assessed the risks of the project as required by NEPA, such as threats it posed to Lake Oahe, which the pipeline runs directly under.

On Monday, the same court concluded that the pipeline’s operations—moving up to 570,000 barrels of oil per day—must cease and the pipeline must be emptied of oil by August 5. The agency will conduct the required environmental review in the meantime, a process that’s expected to take up to a year to complete.

The Dakota Access decision encapsulates how longstanding laws like NEPA—while at times unfairly criticized as requiring cumbersome “red tape”—are sometimes all that prevents ill-conceived or risky projects from jeopardizing vital public resources like clean drinking water.

The Dakota Access pipeline is a prime example of how rushing through legal requirements has backfired for federal agencies during the Trump Administration.

The government erred by rushing through the NEPA process, forgoing the careful environmental review required by law. The court found the agency’s initial analysis so severely lacking that the “potential harm each day the pipeline operates” outweighed concerns over “the disruption such a shutdown will cause.” The agency will now prepare a new analysis, and the proposed timeline means the ultimate fate of the pipeline is uncertain, especially considering November’s election. A new Biden administration could decide to not reissue the project’s authorizations and halt it entirely.

The Trump Administration is seeking to scale back the NEPA environmental review process altogether, through new regulations. But these regulations don’t alter the existing NEPA statute, so the Administration’s effort may ultimately backfire.

Under the Trump Administration, certain agencies have started to forgo a full assessment of environmental effects—especially climate change effects—but the old rules haven’t been overturned yet. This can have high costs. For instance, federal courts recently found the Department of the Interior’s analysis of climate change and groundwater effects from federal oil and gas lease sales deficient, leading to lease sale delays and cancellations. Other projects that use the new regulations as an excuse to ignore NEPA requirements could face a similar fate.

Environmental advocates have a number of avenues for challenging projects, and many of these strategies are increasingly working due to governmental sloppiness. In April, a federal district court overturned blanket federal permit authority for pipelines and powerlines to cross waterbodies and wetlands. The court ruled that the Army Corps of Engineers erred by forgoing a required Endangered Species Act consultation before reauthorizing the nationwide permit in 2017, and vacated the nationwide permit until the agency completes the consultation process. This is ultimately what paused the Keystone XL pipeline—on Monday, the U.S. Supreme Court left the district court order in force with respect to Keystone, refusing to let construction start on the project. The court did allow the Army Corps to resume issuing permits for other oil and gas pipelines while the legal issues are resolved.

Environmental advocates have a number of avenues for challenging projects, and many of these strategies are increasingly working due to governmental sloppiness.

The cumulative effects of these legal challenges are mounting.

Due in part to ongoing litigation risk and delays, Dominion and Duke Energy announced this week that they are cancelling the 600-mile Atlantic Coast Pipeline, which would have tunneled beneath the Appalachian Trail on its route from West Virginia to North Carolina. The cancellation is especially remarkable, as it follows a favorable ruling from the Supreme Court in June upholding the project’s right of way to be built beneath the Appalachian Trail.

But the utilities said that the $8 billion project had become too costly and still faces multiple legal risks, including with respect to the permit authority at issue in Keystone XL. Even more strikingly, Dominion seems to see the writing on the wall with respect to natural gas infrastructure more generally. It announced this week that it will sell all of its natural gas transmission and storage operations.

Together, these groundbreaking legal and business decisions mark a turning point for longstanding advocacy against pipelines and other fossil fuel infrastructure. And while they don’t represent any sort of change of heart in the federal government, they can be understood as examples of the laws we already had on the books working—and working particularly well in the face of incompetence. They also serve as a harbinger of future costly outcomes, especially when agencies and project proponents cut corners rather than fully analyze environmental effects and engage the public in decision making.