CHICAGO — The president on Thursday said a tentative railway labor agreement has been reached, averting a potentially devastating strike before the pivotal midterm elections.

President Joe Biden said the tentative deal “will keep our critical rail system working and avoid disruption of our economy.”

Metra was prepared to close service on four of their 11 railways had a strike taken effect. However due to the agreement, on Thursday morning, a spokesperson said the late evening trains that had been cancelled by BNSF and Union Pacific in anticipation of a strike will now run as scheduled.

They issued the following statement:

We are relieved that the freight railroads and the unions have reached a tentative agreement and that our riders will not be impacted by what could have been a significant disruption to service and a setback in our efforts to recover from the pandemic. We would like to thank everyone who helped to reach this agreement. Our riders deserve safe, reliable and consistent service and we are grateful we will be able to continue to provide it.

Biden believes unions built the middle class, but he also knew a rail worker strike could have badly damaged the nation’s economy. That left him in the awkward position of espousing the virtues of unionization in Detroit, a stalwart of the labor movement, while members of his administration went all-out to keep talks going in Washington between the railroads and unionized workers in hopes of averting a shutdown.

But after a long night, the talks succeeded and Biden announced Thursday that the parties had reached a tentative agreement to avoid a shutdown that would go to union members for a vote. He hailed the deal in a statement for avoiding a shutdown and as a win for all sides.

“These rail workers will get better pay, improved working conditions, and peace of mind around their health care costs: all hard-earned,” Biden said. “The agreement is also a victory for railway companies who will be able to retain and recruit more workers for an industry that will continue to be part of the backbone of the American economy for decades to come.”

Passenger and commuter trains would have been affected by freight railroad negotiations because — while they are not specifically a part of any freight railroad companies or unions — they do operate on freight company owned and operated railroads, meaning if the freight railroads are not being maintained and operated, passenger and commuter trains cannot use them.