OTTAWA — In an extraordinary move aimed at boosting Canada’s tar sands industry in the wake of sharp environmental opposition, the Canadian government said Tuesday that it will spend $3.5 billion to buy the Trans Mountain pipeline and triple its capacity.

The move to buy the pipeline from an affiliate of U.S.-based pipeline company Kinder Morgan follows the company’s threat to pull the plug on the expansion because of delays caused by opponents of the project. They are led by British Columbia, which is trying to stop the pipeline development in the courts on environmental grounds.

The announcement was made by Canada’s finance minister, Bill Morneau, who called the proposed purchase “an investment in Canada’s future.” While British Columbia has battled the project, Alberta has been a major backer, leading to increasingly testy battles between the two governments and calls for Ottawa to intervene.

The move is a calculated political risk for Prime Minister Justin Trudeau, who has embraced the Paris environmental accord and the need for Canada to fight climate change. He insists there is no contradiction between fighting for the environment and defending Canada’s oil industry and the economic benefits it brings.

The Trans Mountain project is designed to increase capacity of the 65-year-old pipeline from Edmonton, Alberta, to Burnaby, B.C., from 300,000 to 890,000 barrels per day. Because of pipeline bottlenecks and growth in output, the crude oil transported from northern Alberta has been selling at a substantial discount.

“It will ensure that we are about to safely get Canadian oil resources to world markets, where we can get a fair price for them,” Morneau said.

“This is a major step forward for all Canadians,” tweeted Rachel Notley, the premier of Alberta. Steven J. Kean, the president of Kinder Morgan, called it a “great day for Canada, for our customers and for our employees.” He said that shareholders would receive a “fair price” for the assets.

Kean said the Canadian government would help search for an alternative buyer. But if one isn’t found by July 22, Kinder Morgan’s stake in the pipeline would be bought out by the Canadian government, which would proceed with the expansion, whose cost has been estimated at about $5.7 billion. Morneau declined to say what the government’s ultimate financial outlay would be.

But John Horgan, the premier of British Columbia, said the federal government’s purchase won’t halt his province’s court challenge. “I’m concerned there could be catastrophic consequences from a diluted bitumen spill, regardless of the owner of the pipeline,” Horgan said.

Environmental activists and their allies among indigenous groups say the development will increase the risk of oil spills from the pipeline and from oil tankers along British Columbia’s coastline. There is also objection to the high greenhouse gas emissions from the processing of tar sands.

“It’s outrageous that Trudeau is using public funds to bail out a multinational corporation when we would create more jobs by investing in building a clean-energy economy instead,” Caitlyn Vernon, campaigns director of Sierra Club BC, told the Vancouver Sun.

Morneau, the finance minister, called the deal to buy the pipeline a “a commercial agreement” and insisted that the Canadian government didn’t intend to remain owner of the facility. He said that the pipeline had “significant commercial value” and that the government intends to sell it to private investors over time.

The Alberta government also has pledged a contingency fund of up to about $1.5 billion to provide emergency funds to the project if unforeseen circumstances arise. In return, the province would receive an equity or other stake in the pipeline, depending on the size of its investment.

Under the agreement between the federal government and Kinder Morgan, the company would resume construction on the project, which was put on hold in April. Ottawa would provide a federal loan guarantee to the company in the meantime.

There is a long history of state involvement in large Canadian business enterprises. But over the past 30 years, the Canadian government has launched a major privatization effort, selling Air Canada, Canadian National Railway and Petro-Canada.

Alberta’s oil industry has seen its attempts to have other pipeline projects built sunk by regulatory and political opposition, including cross-border projects such as Keystone XL, still stalled because of opposition in Nebraska and South Dakota. Trans Mountain was seen as the one with the best chance of getting public approval because it would largely involve expanding an existing line rather than building a new one from scratch.