A federal judge ordered the shutdown of the Dakota Access Pipeline and that it be emptied, while a lengthy environmental review is conducted.

The pipeline must be emptied by August 5, the court ordered Monday, after finding that the U.S. Army Corps of Engineers violated “the National Environmental Policy Act when it granted an easement” for the pipeline’s construction and operation of crude-oil running beneath Lake Oahe.

U.S. District Judge James Boasberg wrote in a 24-page order that he was “mindful of the disruption such a shutdown will cause,” but said he had concluded that it was necessary.

“Clear precedent favoring vacatur during such a remand coupled with the seriousness of the Corps’ deficiencies outweighs the negative effects of halting the oil flow for the thirteen months that the Corps believes the creation of an EIS will take,” Boasberg wrote.

FLASHBACK: NORTH DAKOTA REGULATORS APPROVE DAKOTA ACCESS PIPELINE EXPANSION DESPITE PUSHBACK

The environmental review for the pipeline, which has been in operation for three years, must be completed within 30 days, according to the judge's order.

In this Oct. 5, 2016, file photo, heavy equipment is seen at a site where sections of the Dakota Access pipeline were being buried near the town of St. Anthony in Morton County, N.D. (Tom Stromme/The Bismarck Tribune via AP, File)

The decision comes after the Standing Rock Sioux Tribe requested the pipeline be shut down for fear of environmental harm.

The $3.8 billion, 1,172-mile underground pipeline sparked months of protests, sometimes violent, during its construction near the Standing Rock Sioux Reservation that straddles the North Dakota-South Dakota border.

HOUSE DEMS TURN TO 'ENVIRONMENTAL JUSTICE' WITH MASSIVE CLIMATE CHANGE BLUEPRINT

The pipeline carries oil from North Dakota across South Dakota and Iowa and to an oil terminal in Illinois, where it is shipped. Its route crosses beneath the Missouri River, just north of the reservation.

The tribe draws its water from the river and fears pollution despite the pipeline's Texas-based owner, Energy Transfer, insisting the pipeline would be safe.

Jan Hasselman, an attorney for the Standing Rock tribe, tweeted news of Boasberg's ruling and said: “Stunning.”

Boasberg in 2017 ruled that the U.S. Army Corps of Engineers “largely complied” with environmental law when permitting the pipeline but ordered more review. He said the agency didn’t adequately consider how an oil spill under the Missouri River might affect the Standing Rock Sioux tribe’s fishing and hunting rights, or whether it might disproportionately affect the tribal community.

After completing more than a year of additional study of the pipeline, the Corps in 2018 said the work substantiated its earlier determination that the pipeline poses no significant environmental threats. However, the tribe maintained the study was flawed.

The Corps had planned for a full environmental review in 2017 after the Obama administration rejected permits for the project. But in Feb. 2017, shortly after President Trump took office, the Corps scrapped the review and granted permits for the project.

The agency had said the pipeline posed no significant environmental issues after an additional year of review, as ordered by the court.

Before the coronavirus pandemic devastated the U.S. oil industry, daily oil production in North Dakota — the nation’s No. 2 oil producer behind Texas — was at a near-record 1.45 million barrels daily. The state’s output has slipped to below 1 million barrels daily amid low energy prices and sparse demand.

The order to shut down the Dakota Access Pipeline is the second major blow to the expansion of oil and natural gas development and their respective industries in just this week.

CLICK HERE TO GET THE FOX NEWS APP

A day earlier, Duke Energy & Dominion Energy announced that they were scrapping plans for the Atlantic Coast Pipeline due to ongoing delays and increasing cost uncertainty, which threatens the economic viability of the project.

"This announcement reflects the increasing legal uncertainty that overhangs large-scale energy and industrial infrastructure development in the United States," Thomas F. Farrell, II, Dominion Energy chairman, and Lynn J. Good, Duke Energy chair, said in a joint statement. "Until these issues are resolved, the ability to satisfy the country’s energy needs will be significantly challenged.”

Fox News' Kellianne Jones and Bill Mears, along with The Associated Press contributed to this report.