"Bankruptcy is not a licence to ignore rules."

Dan Riedlhuber / ReutersAn abandoned well site near Lloydminster, Sask., Aug. 27, 2015. The Supreme Court says a bankrupt Alberta energy company cannot simply walk away from unprofitable wells on agricultural land without having to clean up.

OTTAWA — The Supreme Court of Canada says the trustee for a bankrupt Alberta energy company cannot simply walk away from unprofitable wells on agricultural land without having to clean up.

The high court's 5-2 ruling comes with a recommendation from Chief Justice Richard Wagner for Parliament to clarify the confusion between the federal bankruptcy law and the regulations provinces rely on to protect the environment.

"Bankruptcy is not a licence to ignore rules, and insolvency professionals are bound by and must comply with valid provincial laws during bankruptcy," Wagner wrote.

Watch: The 5 largest sources of Canada's oil imports. Story continues below.

Thursday's ruling overturns an Alberta Court of Appeal ruling that upheld a 2016 decision in the Alberta Court of Queen's Bench that allowed a bankrupt energy company to sever its connection with unprofitable and unreclaimed wells when the company's assets were sold off to creditors, as if the wells were debts that the company couldn't cover.

Alberta's energy regulator and the Orphan Well Association, an industry-funded group that cleans up wells that have been left unreclaimed, appealed the ruling to the high court.

"The end-of-life obligations the Regulator seeks to enforce against Redwater are public duties. Neither the regulator nor the Government of Alberta stands to benefit financially from the enforcement of these obligations," Wagner wrote. "These public duties are owed, not to a creditor, but, rather, to fellow citizens, and are therefore outside the scope of 'provable claims'."

Martin interpreted Parliament's intent in writing the law as "aimed at concerns about the protection of trustees, not the protection of the full value of the estate for creditors," Wagner wrote. "I agree with Martin ... that there is no basis on which to read the words 'the trustee is not personally liable' in s.14.04(4) as encompassing the liability of the bankrupt estate."

Since the case went to court, an estimated 1,800 wells representing more than $100 million in liabilities have been abandoned.

A group with the support of thousands of farmers also wanted to see the high court reverse the decision. The Action Surface Rights Association intervened in the case because it believes rights of landowners have been overlooked in the case.