PORTLAND — A bankrupt railroad whose runaway train killed 47 people when it derailed and exploded in Quebec has hired a Portland law firm.

A bankruptcy judge on Tuesday agreed to allow Montreal, Maine & Atlantic Railway to hire Verill Dana to represent the company during the bankruptcy process.

Company trustee Robert Keach said the goal is to sell the Maine-based railroad by year’s end. The company says the sale is necessary to repay creditors and victims following the July 6 disaster.

The sale of the Hermon-based railroad would have to be approved by U.S. Bankruptcy Court. If a buyer purchases all 512 miles of rail in Maine and Canada, then the deal would have to be approved by officials in both countries.