A US judge on Monday ordered the closure, at least temporarily, of the Dakota Access Pipeline, which has been the subject of dispute and massive protest for years by Native American tribes and environmental groups.

Activists protested and blocked construction of the controversial $3.8-billion, 1,172-mile oil pipeline for months in 2016, objecting to the route connecting the Bakken and Three Forks oil production areas in North Dakota to a distribution center in Illinois.

Washington-based federal judge James E. Boasberg ruled the pipeline falls far short of environmental standards, particularly when it comes to preventing oil spills.

In his 24-page order, he suspended an operating permit granted by the US Army Corps of Engineers to the company Energy Transfer to build a portion of the pipeline under Lake Oahe that stretches from South Dakota into North Dakota in the Northwest United States.

"Fearing severe environmental consequences, American Indian tribes on nearby reservations have sought for several years to invalidate federal permits allowing the Dakota Access Pipeline to carry oil under the lake," Boasberg wrote.

"Today they finally achieve that goal -- at least for the time being."

The ruling means the pipeline must be emptied of oil by August 5 while the Army Corps of Engineers prepares an environmental impact statement -- a step that it had forgone in approving the pipeline.

Protests against the Dakota Access Pipeline raged for months in North Dakota in 2016
Protests against the Dakota Access Pipeline raged for months in North Dakota in 2016 AFP / Robyn BECK

The ruling is a setback for President Donald Trump, who relaunched the Dakota Access Pipeline shortly after taking office in January 2017, alongside the Keystone XL, another controversial oil pipeline.

Both projects had been frozen under his predecessor Barack Obama.

The Standing Rock Sioux Tribe and Cheyenne River Sioux Tribe sued over Trump's decision, claiming the pipeline threatened their drinking water and degraded sacred sites.

In a statement to AFP, Energy Transfer said it would ask the court to stay the decision, or appeal Monday's ruling.

"We believe that the ruling issued this morning from Judge Boasberg is not supported by the law or the facts of the case," spokeswoman Lisa Coleman said.

"Furthermore, we believe that Judge Boasberg has exceeded his authority in ordering the shutdown of the Dakota Access Pipeline, which has been safely operating for more than three years."