Canada’s biggest railway reached a last-minute tentative agreement with one of its unions on Monday, averting a lockout that threatened to delay imports from Asia and compound a U.S. West Coast port logjam.

Canadian National Railway Co and Unifor, the union representing its 4,800 mechanical, clerical and trucking workers, struck a deal just before the railway’s 11 p.m. EST Monday deadline to lock out the workers.

“I’m delighted to say that Unifor and Canadian National Railway have been able to come to a tentative agreement,” Canadian Labor Minister Kellie Leitch told Reuters outside the bargaining room. “CN will be running at full capacity tonight and tomorrow.”

CN Rail operates freight trains on tracks across Canada and the United States, but Unifor represents only Canadian workers.

The two main unresolved issues had been pay and benefits, a Unifor official said earlier on Monday. Neither Leitch nor Unifor National President Jerry Dias gave details of the deal.

“I’m elated, it came right down to the wire,” Dias told Reuters. “(Leitch) found a way to make sure the corporation knew that there had to be a negotiated settlement, and her strong statements in that regard were pivotal.”

A lockout could have spurred disruptions of shipments of grain and other commodities and goods across Canada and impede operations at the country’s biggest port, Vancouver.

Ontario-based automakers such as Ford Motor Co., Honda Motor Co. Ltd. and General Motors and crude by rail shippers such as Keyera Corp. were monitoring the situation.

Retail companies and ports, particularly on the Pacific Coast, had feared the impact of a lockout at CN Rail.

British Columbia’s Port of Prince Rupert is only served by CN and “practically all” of its cargo moves via rail on about 20 trains a day, a port spokesman said. Roughly 50-70 percent of the port’s containers are bound for the United States.

Port Metro Vancouver, the country’s biggest, said a disruption would have “potential long-term effects.”

U.S. West Coast ports only resumed full operations over the weekend after a tentative labor deal late Friday ended a dispute that has caused months of disruption to trade, but port officials said it would take six to eight weeks to clear a backlog of containers.

The Retail Council of Canada had asked the government to step in to help avert a strike, saying even a short disruption could have a major impact on retailers as many keep only minimal inventory.

Canada’s Conservative government said it would not introduce back-to-work legislation earlier on Monday. In 2012, the government ended a nine-day Canadian Pacific Rail strike with such legislation.

“They’ve been meticulous about trying to avoid any kind of work stoppage,” said George Smith, a labor relations expert at Queen’s University and a former Air Canada executive.

Canada’s two major railways have had fraught relationships with their unions. They have pushed hard to bring down operating costs and move freight more efficiently, putting pressure on unions to relax strict work rules.

Last week, train crews at CP Rail halted a one-day strike after the two sides agreed to seek arbitration on a new contract. It was the second strike at Canada’s No. 2 railway in three years.

Separately on Monday, Canada’s transportation safety watchdog released an update on its investigation into a recent CN Rail derailment and said it showed the need for tougher rail car standards.