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

Judge Louis Kornreich in U.S. Bankruptcy Court in Bangor said the railroad may 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 debts.

Railway 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.

“The judge authorized the railroad to pay all of its payroll and approved an order that allows the railroad to use its cash to pay operating expenses,” 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 oil train caused an explosion that killed 47 people in Quebec on July 6, asked courts in Maine and in Quebec on Wednesday to grant protection from creditors. The Maine filing was made under Chapter 11 of the U.S. Bankruptcy Code.

The railway 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.

MM&A, which operates in Maine, Vermont and Quebec, owns 512 miles of line and has 54 employees in Maine and 34 employees in Canada. Most of its workers have been laid off since the accident disrupted operations. Its headquarters are in Hermon.

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

Court documents show that the company’s liability insurance policy in Canada covers only $25 million for property damage, bodily injury, fire suppression and environmental cleanup.

In court Thursday in Bangor, Judge Louis Kornreich stressed that it is essential to international commerce to keep railroads running. The next hearing is set for 11 a.m. Aug. 22 in Kennebec County Superior Court in Augusta.

“There’s no question that the bankruptcy code provides that it’s critically important that railroads remain in operation,” Clement said. Railroads are not even permitted to file Chapter 7 bankruptcy, which issued when a company closes its business or sell off its assets, he said.

Clement said it is unlikely the railroad will cease operations, but the company will not be hauling 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 the state will help make sure that railroad lines remain operating during the bankruptcy proceedings, according to The Associated Press. David Bernhardt said that three railroads that operate in Maine have been contacted to see if they would be interested in operating the lines now owned by MM&A, if necessary, the news service reported.

Also Thursday, the railroad’s sister company, Montreal, Maine & Atlantic Canada, was granted bankruptcy protection by a Quebec Superior Court in Montreal. The protection from creditors was needed to “prevent anarchy,” Justice Martin Castonguay told the Montreal courtroom.

, according to CBC News.

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

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

The company is facing at least one such lawsuit from victims and family members of victims of the July 6 accident in Quebec, but those victims may ultimately receive little compensation.

Any wrongful-death claims awarded by the courts would be added to the list of unsecured claims against the bankrupt company, said Lois Lupica, a bankruptcy expert and Maine Law Foundation Professor of Law at the University of Maine School of Law. That means those plaintiffs would be at the end of the line to receive any money from the company, effectively sharing what is left over after payments are made to top-priority creditors who have liens, or collateral.

Portland Press Herald staff writer Craig Anderson contributed to this report.