A federal judge has ordered a temporary halt to construction of the controversial Keystone XL pipeline, ruling that the Trump administration didn’t properly consider the environmental consequences before pushing ahead with the enormous oil project.

The US state department “simply discarded” its previous analysis of the pipeline’s climate change impact by approving it shortly after Donald Trump’s presidency began, wrote Brian Morris, US district court judge in Montana.

Morris ruled the Trump administration “jumped the gun” by pushing forward with the pipeline despite concerns over damage to Native American heritage and the resulting release of greenhouse gases.

The judge ordered TransCanada, the company behind the project, to halt work on Keystone while the US government conducts a more thorough review of its impact.

“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’s judgment read.

Activists welcomed the development.

“This is a complete repudiation of the Trump administration’s attempts to evade environmental laws and prioritize oil company profits over clean water and wildlife,” said Jared Margolis, senior attorney with the Center for Biological Diversity, which is part of a coalition of environmental and native groups that have attempted to stymie the pipeline.

“Keystone XL would devastate species and put communities at risk of contamination. There’s simply no excuse for approving this terrible project. We need to move away from fossil fuel dependence, not support more devastation,” Margolis added.

The decision is a blow to Trump, who signed an executive order after just two days in the White House to grant a permit for the construction of Keystone XL and Dakota Access, another bitterly opposed project that sparked fierce protests form Native American groups.

Trump claimed there would be “great construction jobs” stemming from Keystone XL, which involves the building of a 1,200-mile pipeline across six US states in order to bring crude oil from Alberta in Canada to refineries on the Gulf coast. The pipeline would link up with an existing infrastructure in Nebraska, allowing 800,000 barrels of petroleum to flow to the Gulf refineries.

Keystone XL roused a major environmental protest movement during Barack Obama’s presidency, leading to arrests outside the White House and promises by activists to harass construction along the pipeline’s route. The Obama administration stalled the project, only for Trump to revive it.

Morris’s order does not permanently extinguish hopes Keystone XL will go ahead, but it will require the administration to come up with a better explanation as to why it should proceed. The Trump administration has regularly run afoul of the courts in its attempts to repeal environmental rules and approve fossil fuel projects.

Opposition to the Keystone XL pipeline has centered on climate change concerns, as well as potential damage to endangered species and to local landowners, including Native Americans, whose land would be dug up for the pipeline.

“We sleep well tonight and tomorrow we continue to keep our guard up, working stronger as good relatives until Keystone XL vanishes, and it will,” said Faith Spotted Eagle, member of the Yankton Sioux Nation and Brave Heart Society.

John Harter, a South Dakota landowner whose property could be affected by the pipeline, said he was “pleased and surprised” by the decision.

“Basically you just can’t reverse a decision based on environmental and scientific facts just because you feel like it,” he said.

A spokesman for TransCanada said: “We have received the judge’s ruling and continue to review it. We remain committed to building this important energy infrastructure project.”