“THIS is huge,” crowed one prominent environmental campaigner. He was celebrating Barack Obama’s decision on November 6th to reject the Keystone XL pipeline, which would have carried heavy oil from Canadian tar sands to the United States (see map). To Canada’s prime minister, Justin Trudeau, installed in office just two days before, the decision is both a headache and an opportunity. He will have to come up with a new way of exporting oil without breaking his promise to be a much greener prime minister than his Conservative predecessor, Stephen Harper. Protests and lobbying will now move from Washington to Ottawa. But Keystone XL’s demise, weeks before a UN conference on climate change in Paris, will make it easier for Mr Trudeau to forge a national consensus on climate policy and to portray Canada as a helpful partner at the global gathering.

The thumbs-down for Keystone XL, which would have carried 830,000 barrels of oil a day, was not quite as beneficial for the environment as campaigners claimed. Canada is shipping record amounts of crude oil, about 3m barrels a day, to the United States through 31 pipelines. About half is heavy bitumen from Alberta’s tar sands, or synthetic oil made from it. That will continue to grow for a while, even though extracting tar-sands oil is expensive and oil prices are weak. Low prices depress future investment, but producers have already spent billions to exploit Alberta’s reserves.

What does not fit into the pipelines will be carried by rail, which is more dangerous, dirtier and more expensive. Two years ago 47 people were burnt to death in a derailment in Lac-Mégantic in Quebec. This month a train derailed in Wisconsin, spilling hundreds of gallons of crude.

Still, the environmentalists’ victory is not an empty one. Burning tar-sands oil emits about a fifth more carbon than using conventional petroleum. Without Keystone XL to make it more competitive, more of it is likely to stay in the ground.

Until, that is, Canada comes up with an alternative. Alberta’s oil producers are still intent on shifting transport from rail to pipeline. Mr Trudeau does not want to disappoint them. His Liberal Party won four seats in Alberta in October’s election, matching its best showing since his father, Pierre, a long-serving prime minister, enacted an unpopular national energy programme in 1980. The Liberals do not want to alienate the province again.

But Mr Trudeau will have to reconcile appeasement of Alberta with the Liberals’ many environmental promises. These include modernising the National Energy Board (the main regulator); assessments that consider energy projects’ downstream effects, such as carbon emissions, along with their impact on the local environment; and closer consultation with aboriginal peoples on regulation and on how the pipelines are operated and maintained. The day after Mr Trudeau and his cabinet were sworn in, a small group of demonstrators showed up in Ottawa to demand an end to development of the tar sands.

He has already ruled out one pipeline on environmental grounds: the Northern Gateway, which would have carried 525,000 barrels of oil a day over the Rockies from Alberta to the coast of British Columbia. That leaves two other big projects. Energy East could carry 1.1m barrels a day to a port on the Atlantic coast. Another option is to increase the capacity of the existing TransMountain pipeline by nearly threefold, to bring 890,000 barrels a day to Vancouver, an outlet to Asia. Energy East looks like the favourite; the premiers of Alberta and New Brunswick, where the pipeline would begin and end, are keen. It also needs consent from the more sceptical leaders of Ontario and Quebec.

Mr Obama did the new prime minister a favour by quashing Keystone XL so early in his term, relieving him of any blame for the decision. The rejection will also help Mr Trudeau to persuade provincial premiers that Canada needs a national plan to cut carbon emissions if it is not to face discrimination from importers. The help from the American president ends there. Mr Trudeau must handle the tricky task of selling dirty oil in a green way on his own.