WASHINGTON - Congress gave the nation's railroads three more years - and possibly up to five - to install a mandated safety system that would automatically slow trains running at unsafe speeds, and which safety experts say could have prevented May's deadly Amtrak derailment in Philadelphia.

Called positive train control, the system was supposed to be installed on major passenger and freight lines by the end of this year, but no freight lines and only a handful of commuter railroads expected to meet that target. They now will have until at least Dec. 31, 2018, with the potential for extensions up to the end of 2020.

The new deadline, sought by railroads and opposed by safety advocates, was approved with unusual speed in voice votes by the House and Senate on Tuesday and Wednesday. It was attached to a critical measure to keep highway programs funded ahead of a Thursday deadline. Approving the measure by voice votes means few lawmakers are on record supporting the delay, providing political cover if there's another train crash.

President Obama is expected to sign the bill this week, according to congressional aides.

Lawmakers from both parties realized that the railroads needed the extension, but they had debated how firm the new deadline should be.

SEPTA is one of the few rail systems that anticipated meeting the original deadline, but the agency's general manager, Jeff Knueppel, said the delay "does afford us some room for margin of error."

NJ Transit said it could not install the train control system until 2018.

"This deadline extension provides us with a reasonable and achievable goal of 2018 implementation," executive director Ronnie Hakim said in a statement.

Portions of the Northeast Corridor controlled by Amtrak should have the system installed by the end of this year, Amtrak said Wednesday.

Sen. Barbara Boxer (D., Calif.), who helped set the positive train control deadline in 2008, blasted the extension and the process that got it approved, saying it had been "cherry-picked" and added to a must-pass transportation funding bill to satisfy the railroad lobby.

No other measures got such treatment, she said. "It's the only provision that benefits one special interest."

Sen. Richard Blumenthal (D., Conn.) said the new timeline suggests that deadlines "can be avoided without repercussions."

Railroads, though, said that the original deadline was unrealistic and that they have been hampered by budget shortfalls and technical hurdles. Freight lines have spent about $6 billion on the train control, but none will have the system in place by year end, according to industry groups. Freight and commuter lines have warned that they may have to cease operations without an extension.

"We didn't have the luxury of time," Sen. John Thune (R., S.D.) said on the Senate floor, warning of devastating economic effects if businesses and commuters were unable to rely on rail. "Together we have averted the potential harm that would come with a congressionally caused rail shutdown."

He added that the framework of the extension had previously been debated and not "sprung on members." He stressed that the delay requires annual progress reports from railroads and potential fines for those that fall behind their benchmarks.

Positive train control can remotely brake speeding trains. The National Transportation Safety Board has called for its installation since 1970, saying the system could have prevented 140 accidents that resulted in nearly 300 fatalities since then.