The judge added that the Trump administration had not adequately accounted for potential declines in oil prices, which have been depressed since the crash of 2014, and which would have a major effect on the long-term viability of such a project.
Environmental and indigenous groups sued TransCanada and the State Department in March to halt the project.
TransCanada Corp's almost 1,200-mile pipeline has become one of the major battlegrounds in the climate change debate and, if completed, would carry an estimated 800,000 barrels per day from Canada's tar sands pits to Gulf Coast refineries in the US.
What is the Keystone XL Pipeline?
In a setback for the Trump administration, a federal judge has blocked a permit for construction of the Keystone XL oil pipeline from Canada and ordered officials to complete an environmental review.
He said it could take several months before the State Department is able to issue a new environmental impact statement, putting a timeline for a decision "well into 2019". Native American groups in Montana and elsewhere fought the Keystone project as well, saying its route failed to adhere to historical treaty boundaries and would impinge on their water systems and sacred lands. The Trump administration has regularly run afoul of the courts in its attempts to repeal environmental rules and approve fossil fuel projects.
But on Friday McCuaig Boyd said Notley's New Democratic Party government had always supported the Keystone XL plan.
The proposed US portion of the pipeline would run about 875 miles through Montana, South Dakota and Nebraska. The order came as a Canadian energy company prepared to assemble initial stages of the 1,200-mile long, cross-border project.
One of those litigants in this case, the Sierra Club, cheered the decision on substantive grounds.
As The Post's Steven Mufson reported, activists say the pipeline would be especially damaging to the climate because it would mean extracting thick, low-quality oil from Canada's oil sands, with lots of tree-cutting and energy consumption in the process which would increase greenhouse gas-emissions.
In 2015, on the eve of the global climate talks in Paris, the Obama administration appeared to bring an end to the seven-year-long saga when it announced it was halting construction of the pipeline, arguing that approval would compromise the country's effort to reduce its greenhouse gas emissions.
"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.
"This is a win for Lakota, the Oceti Sakowin and other Tribal Nations, for the water, and for the sacredness of Mother Earth", Tom Goldtooth, executive director for the Indigenous Environmental Network, said in astatement.