A federal judge authorized the Montreal, Maine & Atlantic Railway on Thursday to keep running and pay its expenses while it seeks to reorganize under bankruptcy protection.

Judge Louis Kornreich said in U.S. Bankruptcy Court in Bangor that the railroad can continue to pay all of its employees and manage its funds, a first legal step that gives the company time to reorganize or seek a buyer despite its mounting debt.

The railroad’s attorney, Roger A. Clement Jr., said the ruling allows the railroad, as a debtor, to stay in business until a Chapter 11 trustee is appointed to oversee operations.

Clement said, “If we didn’t pay our employees, we wouldn’t have a railroad to run. … We need special approval for that and it was given today in this case.”

The railroad, whose runaway train carrying crude oil caused an explosion that killed 47 people in Lac-Megantic, Quebec, on July 6, asked courts in Maine and Quebec on Wednesday to grant it protection from creditors. The Maine filing was made under Chapter 11 of the U.S. Bankruptcy Code.

The railway based in Hermon is worth $50 million to $100 million and owes about $39 million to its largest creditors, according to the Maine filing.

Its Canadian-based sister company has just under $18 million in assets, according to court documents in Canada.

The Montreal, Maine & Atlantic, which operates in Maine, Vermont and Quebec, owns 512 miles of line and has 54 employees in Maine and 34 in Canada. Most of its workers have been laid off since the accident disrupted operations.

The railroad faces several lawsuits, and estimates that cleanup costs alone from the disaster will surpass $200 million.

In court Thursday in Bangor, the judge said it is essential to international commerce to keep the railroads running. The next bankruptcy hearing is set for 11 a.m. Aug. 22 in Kennebec County Superior Court in Augusta.

Clement said railroads are not permitted to file Chapter 7 bankruptcy, in which a company closes or sells off its assets.

He said it is unlikely that the railroad will cease operations, but it will not haul crude oil anytime soon. He said the rail line to Lac-Megantic is expected to be reopened soon for freight deliveries.

Maine’s transportation commissioner said Thursday that the state will help to make sure that railroad lines operate during the bankruptcy proceedings, according to The Associated Press. David Bernhardt said three railroads that operate in Maine have been asked whether they would be interested in operating the lines now owned by Montreal, Maine & Atlantic, if necessary.

Also Thursday, the railroad’s sister company, Montreal, Maine & Atlantic Canada, was granted bankruptcy protection by Quebec Superior Court in Montreal.

The protection from creditors was needed to “prevent anarchy,” said Justice Martin Castonguay, according to CBC News.

Castonguay said he was not impressed with the railway’s application for bankruptcy protection and the way it has conducted business since the disaster but, in light of the circumstances, there was no alternative to granting the application.

The railway’s insurance company also received a stay of proceedings, which means that the class-action lawsuits that have been filed cannot go forward for the time being, according to CBC News.

The company faces at least one such lawsuit from victims and family members of victims, but those plaintiffs may ultimately receive little compensation.

Any wrongful-death claims awarded to residents of Lac-Megantic would be added to the list of unsecured claims against the company, said Lois Lupica, a professor at the University of Maine School of Law who is a business bankruptcy expert. That means those plaintiffs would be at the end of the line to receive any money from the company, after other creditors.

– Staff Writer Craig Anderson contributed to this report.