A federal judge in Montana halted construction of the Keystone XL oil pipeline on Thursday on the grounds that the U.S. government did not complete a full analysis of the environmental impact of the TransCanada project.

The ruling deals a major setback for TransCanada and could possibly delay the construction of the $8 billion, 1,180 mile (1,900 km) pipeline.

The ruling is a victory for environmentalists, tribal groups and ranchers who have spent more than a decade fighting against construction of the pipeline that will carry heavy crude to Steele City, Nebraska, from Canada's oilsands in Alberta.

U.S. District Court Judge Brian Morris' ruling late on Thursday came in a lawsuit that several environmental groups filed against the U.S. government in 2017, soon after President Donald Trump announced a presidential permit for the project.

Morris wrote in his ruling that a U.S. State Department environmental analysis "fell short of a 'hard look"' at the cumulative effects of greenhouse gas emissions and the impact on Native American land resources.

He also ruled the analysis failed to fully review the effects of the current oil price on the pipeline's viability and did not fully model potential oil spills and offer mitigations measures.

In Thursday's ruling, Morris ordered the government to issue a more thorough environmental analysis before the project can move forward.

"The Trump administration tried to force this dirty pipeline project on the American people, but they can't ignore the threats it would pose to our clean water, our climate, and our communities," said the Sierra Club, one of the environmental groups involved in the lawsuit.

Trump supported building the pipeline, which was rejected by former President Barack Obama in 2015 on environmental concerns relating to emissions that cause climate change.

Trump, a Republican, said the project would lower consumer fuel prices, create jobs and reduce U.S. dependence on foreign oil.