Judge Brian Morris of the U.S. District Court in Montana issued the order just as the TransCanadacompany was moving materials to begin building its end of the $8 billion pipeline in the northern part of the state early next year, reported the Great Falls Tribune.

The ruling is a major victory for environmentalist groups that sued to stop the project and for the Native American tribes that have protested against it for years.

The judge ruled that a 2014 environmental review the Trump administration relied on to approve the project failed to fully take into account greenhouse gas emissions and climate change effects from the pipeline oil, ignored potential Native American resources that could be affected by the pipeline, lacked updated information on the risk of oil spills and failed to consider the effect of the price of oil on the current viability of the pipeline.

Work cannot proceed until the State Department completes a supplement to the environmental impact statement that complies with the National Environmental Policy Act and the Administrative Procedure Act, Morris ruled.

Environmentalists called the ruling a “major setback” for the pipeline project.

Dena Hoff, a Montana farmer and a member of the Northern Plains Resource Council, a plaintiff in the case, called it a “victory for the rule of law, and a victory for common sense stewardship of the land and water upon which we all depend. Despite the best efforts of wealthy, multinational corporations and the powerful politicians who cynically do their bidding, we see that everyday people can still band together and successfully defend their rights.”

Morris particularly criticized the Trump administration for ignoring the recognized effects of the pipeline on climate change.

Despite the best efforts of wealthy, multinational corporations and the powerful politicians who cynically do their bidding, we see that everyday people can still band together and successfully defend their rights.Dena Hoff, a Montana farmer and member of the Northern Plains Resource Council

He noted that the State Department denied the permit in 2015, relying on climate change information under the Obama administration, which the Trump administration simply dismissed.

The reversal required a “reasoned explanation” but instead the State Department discarded prior “factual findings,” he said.

“An agency cannot simply disregard contrary or inconvenient factual determinations that it made in the past, any more than it can ignore inconvenient facts when it writes on a blank slate,” Morris wrote.

The 1,179-mile Keystone XL Pipeline would transport up to 830,000 barrels a day of crude oil from Alberta, Canada, and the Bakken Shale Formation in Montana over 875 miles to existing pipeline facilities in Nebraska, then on to Oklahoma and the Gulf Coast.

About 250 miles of pipeline would be buried across six counties in Montana.

The latest ruling follows the court’s previous decision in August to require the State Department to also conduct a supplemental environmental impact statement on a new route through Nebraska.

Other plaintiffs in the suit included The Center for Biological Diversity, Friends of the Earth, the Sierra Club, the Natural Resources Defense Council and Bold Nebraska.

Neither TransCanada nor the State Department could immediately be reached for comment on the ruling.