The Dakota Access pipeline must shut down by Aug. 5, a district court ruled Monday in a stunning defeat for the Trump administration and the oil industry.

The decision is a momentous win for American Indian tribes that have opposed the Energy Transfer Partners LP project for years. It comes just a day after developers scuttled another project, the Atlantic Coast natural gas pipeline, after years of legal delays.

Pipeline opponents have increasingly taken to the courts to oppose fossil fuel infrastructure projects, claiming at least three big victories this year.

The U.S. District Court for the District of Columbia said a crucial federal permit for Dakota Access fell too far short of National Environmental Policy Act requirements to allow the pipeline to continue operating while regulators conduct a broader analysis the court ordered in a previous decision.

The ruling scraps a critical permit from the Army Corps of Engineers, and requires the pipeline to end its three-year run of delivering oil from North Dakota shale fields to an Illinois oil hub. Judge James E. Boasberg said Dakota Access must shut down the pipeline and empty it of oil by Aug. 5.

“Today is a historic day for the Standing Rock Sioux Tribe and the many people who have supported us in the fight against the pipeline,” tribal Chairman Mike Faith said in a statement. “This pipeline should have never been built here. We told them that from the beginning.”

The Army Corps and Justice Department didn’t immediately respond to requests for comment, including on whether it intends to appeal the ruling. Energy Transfer also didn’t immediately respond. The company’s shares fell as much as 3.8 per cent on Monday morning while most other pipeline operators rose.

Years of Opposition

Boasberg’s decision comes after four years of litigation from tribes opposed to Dakota Access’ route across Lake Oahe, a dammed section of the Missouri River just a half-mile from the Standing Rock Indian Reservation.

The Standing Rock Sioux, Cheyenne River Sioux, and others sued the Army Corps for approving the water crossing in 2016, saying it put tribal water supplies and cultural resources at risk.

Their frustrations triggered an outpouring of support from fellow tribes, indigenous advocates, and environmentalists from across the country. Thousands of pipeline opponents camped out in North Dakota for months to show their opposition.

The Obama administration responded by withholding a final permit and committing to a new consultation process, but President Donald Trump quickly put Dakota Access back on track after taking office in 2017.

Kelcy Warren, the billionaire chief executive officer of Energy Transfer, has long been a Trump fan. He recently hosted a fundraiser for the president’s re-election campaign at his private Dallas home.

“My God, this is going to be refreshing,” Warren told investors two days after Trump won the last election.

Despite high-profile opposition to Dakota Access, including from celebrities and some of Warren’s favorite musicians, the Energy Transfer founder has stood by the project, going so far as to say he talks about Dakota Access “like I talk about my son” earlier this year.

“I’m so proud of that project,” he said.

Trouble in Court

But the district court in Washington found flaws in the government’s pipeline approval process. Boasberg ordered the Army Corps to conduct additional environmental review in mid-2017, but allowed the pipeline to remain in service during that time.

Earlier this year, the court again identified shortcomings in the Army Corps’ review, concluding that the agency didn’t fully consider expert disagreement over the risk of an oil spill in Lake Oahe. The Army Corps must do an in-depth environmental impact statement for Dakota Access, the judge said.

Boasberg issued the opinion in March and ordered both sides to submit new briefs explaining whether the pipeline should shut down in light of the decision.

The default consequence for an agency violation of the National Environmental Policy Act is invalidation of the permit at issue, but legal precedent allows courts to balance that outcome against other factors, including how disruptive nixing a permit would be, and how likely an agency is to support its original decision after additional analysis.

The Army Corps has said it expects to finish the court-ordered analysis in mid-2021.

The case is Standing Rock Sioux Tribe v. Army Corps of Engineers, D.D.C., No. 1:16-cv-01534, 7/6/20.

—With assistance from Rachel Adams-Heard