PORTLAND, Maine — The federal Surface Transportation Board has approved Montreal, Maine & Atlantic Railway’s request to abandon 233 miles of rail in northern Maine, paving the way for the state to buy the line and find a new rail operator.

For more than a century, the railroad has carried products in and out of northern Maine. But that nearly came to an end when the rail line asked last year to abandon the line from Madawaska to Millinocket because it was losing millions of dollars.

The state ultimately agreed to pay $20.1 million in cash for the rail, which hauls lumber, paper products, logs and wood chips.

Board Chairman Daniel R. Elliott III says the panel is “pleased to play a role in keeping the trains rolling in northern Maine.”