A Canadian Pacific Railway train is shown in 2012. The Calgary, Alberta-based company is buying Bangor-based Central Maine and Quebec Railway. Credit: Nathan Denette | The Canadian Press via AP

A railway company that owns tracks stretching through much of Canada and parts of the northern U.S. will buy Bangor-based Central Maine and Quebec Railway by the end of the year, adding 481 miles of track in Quebec and Maine to its network.

Canadian Pacific Railway, based in Calgary, Alberta, will buy Central Maine and Quebec Railway from its parent company, New York-based Fortress Transportation and Infrastructure Investors LLC.

The companies expect the sale to close by the end of the year. They did not disclose a sale price.

Central Maine and Quebec Railway’s parent company will keep Katahdin Railcar Services, a 110-acre railcar repair and cleaning facility in Milo.

Canadian Pacific’s president and CEO said the transaction will give its customers access to shipping ports in Searsport and Saint John, New Brunswick.

“This strategic acquisition gives CP a true coast-to-coast network across Canada and an increased presence in the eastern U.S.,” said Keith Creel, the president and CEO.

Central Maine and Quebec Railway owns the section of track that goes through Lac-Megantic, Quebec, where in 2013 a train carrying crude oil went off the tracks, exploded into a ball of fire and killed 47 people.

A few months later, Fortress bought the railroad from Montreal Maine & Atlantic Railway, which went bankrupt after the derailment.