The 5-2 ruling means that the Alberta Energy Regulator, which had appealed the earlier court decisions, can order the cleanup of inactive wells even when their owners have filed for bankruptcy protection.

"Bankruptcy is not a license to ignore rules," the court said in a written decision.

Alberta had 3,127 wells requiring cleanup that had no financially responsible owner - sites that are called orphan wells - as of late January, according to the Orphan Well Association, which is funded by levies paid by Canadian oil producers.

The ruling reduces the cleanup burden on the association, which is overseen by the regulator, but may raise the perceived risk of investing in the Canadian oil industry.

Investors may now avoid companies with higher risk of abandonment liability, such as Cardinal Energy, Bonavista Energy Corp and Obsidian Energy Ltd, analysts at Raymond James said in a note.

The Canadian oil industry has been dogged in recent years by pipeline constraints that have reduced prices and a reputation for environmentally damaging production methods, factors that have driven some investors away.

In 2016, an Alberta judge ruled that proceeds from asset sales of insolvent producer Redwater Energy Corp should go first to secured creditors, rather than towards cleanup. The decision was upheld by the provincial's appeal court.

At the time of Redwater's bankruptcy, it owned 84 wells, most of which were inactive, and owed C$5.1 million to its bank, ATB Financial.

The receiver and trustee in the Redwater proceedings, Grant Thornton, and the Alberta Energy Regulator, could not be immediately reached for comment.

The province's energy minister is scheduled to speak about the ruling later on Thursday.

(Reporting by Dale Smith in Ottawa and Rod Nickel in Winnipeg; Editing by Bernadette Baum)

By Dale Smith and Rod Nickel