US President Donald Trump on Friday denounced a ruling by a federal judge to halt construction of the Keystone XL oil pipeline, saying the decision had been made for political reasons. US District Judge Brian Morris argued that the Trump administration had failed to explain why it had lifted a ban on the project in a stinging setback to the president but a big win for conservationists and indigenous groups. Trump denounced the ruling as "a disgrace" while the Canadian government said it was "disappointed." Trump had granted a permit for the $8 billion conduit meant to stretch from Canada to Texas just days after taking office last year. He said it would create jobs and spur development of infrastructure. In doing so the administration overturned a decision by then-president Barack Obama in 2015 that denied a permit for the pipeline, largely on environmental grounds, in particular US contribution to climate change. The analysis of a cross-border project like this is done by the State Department. The same environmental analysis that the department carried out before denying the permit in 2015 was ignored when the it turned around last year and approved it, Morris found. "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. He added: "The department instead simply discarded prior factual findings related to climate change to support its course reversal." The judge also argued that the State Department failed to properly account for factors such as low oil prices, the cumulative impacts of greenhouse gases from the pipeline and the risk of oil spills. At the White House, Trump decried the ruling as a "political decision." "I think it's a disgrace," he said, adding that it was likely to be reviewed by an appellate court, the Ninth Circuit Court of Appeals, that he also accused of political bias. "We're slowly putting new judges in the ninth circuit." Vanessa Adams, a spokeswoman for Canadian Natural Resources Minister Amarjeet Sohi, said Ottawa was disappointed in the decision. The project is "important for good, middle-class jobs in Canada and for a successful energy export market," she added. Thursday's ruling is temporary, and requires the government to do a more thorough review of how the project might affect the climate, cultural resources and wildlife. In a statement to AFP, pipeline builder TransCanada said it was reviewing the ruling. "We remain committed to building this important energy infrastructure project," spokesman Terry Cunha said. - 'Flawed and dangerous' - The pipeline is designed to run from tar sand oil fields in Canada's Alberta province, through Montana, South Dakota and part of Nebraska, to existing facilities in that last state. From there it would flow to Oklahoma and on to the Texas Gulf Coast. The US stretch of line that needs to be built would be 875 miles (1,450 km) long. Construction of the US leg had been scheduled to begin next year. Environmental and indigenous groups sued TransCanada and the State Department in March to halt the project. One of the plaintiffs, the Sierra Club, welcomed the judge's decision. "Today's ruling makes it clear once and for all that it's time for TransCanada to give up on their Keystone XL pipe dream," Sierra Club senior attorney Doug Hayes said in a statement. "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." Jackie Prange, senior attorney at the Natural Resources Defense Council, also hailed the ruling, saying: "As the court has made clear yet again, the Trump administration's flawed and dangerous proposal should be shelved forever." In Canada, Greenpeace called the decision "a big step backwards" for the project and "a huge win for aboriginal people, the environment and the thousands of people who have been fighting this pipeline for almost 10 years." Also, said Greenpeace spokesman Patrick Bonin, Canadian Prime Minister Justin Trudeau's government should view this decision as a harbinger of "the inevitable legal hurdles it will face if it continues to rush" an unrelated pipeline from Alberta to the Pacific coast. Ottawa nationalized the Trans Mountain pipeline in August, but has had to relaunch a part of the regulatory process after a court quashed its approval, siding with indigenous people worried that increased tanker traffic will harm whales along the coast. Following the ruling, shares in pipeline builder TransCanada Corp closed sharply lower on stock exchanges in New York and Toronto.