Democratic and Republican leaders in Congress vowed on Tuesday to pass legislation averting a nationwide rail strike, saying they agree with President Biden that a work strike just before Christmas would disrupt shipping and deal a devastating blow to the nation's economy.

House Speaker Nancy Pelosi and Senator Chuck Schumer of New York said after a meeting at the White House with Vice President Biden and their Republican counterparts that they would act quickly to move legislation through the chambers.

There will be a bill on the floor tomorrow. We have to avoid a strike because I don't like going against the unions' ability to strike. There will be job losses. Union jobs will be lost.

McConnell said after the meeting that a bill would need to be passed to prevent a railway strike.

It was not an easy call for Congress to intervene in the labor dispute, but Mr. Biden said it was necessary because the economy was at risk.

The rail strike could have a devastating effect on the economic recovery after the coronaviruses. If train lines were frozen, supply chains for commodities would be disrupted and prices would go up even more.

The last time Congress got involved in a rail dispute was in 1992, when the International Association of Machinists went on strike. Two days after the strike began, Congress passed legislation that was signed into law by the president.

Whether it was the agreement that some unions already have voted down, or a less generous proposal that a presidential board issued over the summer, Congress has the authority to intervene.

The tentative agreement between rail companies and the unions will be voted on by the House. Four unions did not vote in favor of the agreement, keeping alive the threat of a strike.

McCarthy said after the meeting that he thought it would pass.

The Senate is expected to vote quickly to do the same.

In the coming days, Mr. Biden will meet with the lawmakers to discuss a number of issues, including funding the government, providing support for Ukraine and protecting same-sex marriage.

Democrats on Capitol Hill are hoping to make the most of the next few weeks while the party still has control of both chambers of Congress. The Republicans will have control over the agenda in the House when the new Congress starts next year.

The president has argued against congressional intervention in railway labor disputes in the past. He was one of six senators who voted against legislation to end the rail workers strike.

The decision to accept congressional action as a solution to the labor dispute could anger some of his biggest supporters in the labor community.

Though many union members are likely to be upset by the prospect of congressional intervention, some union leaders may quietly prefer that intervention to come in December rather than in January, when the House comes under Republican control.

When the last contract expired in 2020, the agreement voted down by several rail unions would raise wages by 25%. Rail workers argue that it does not go far enough to resolve what they say are punishing schedules that affect their health and personal lives.

A shortage of equipment and drivers would make it impractical to rely on trucks to work around a rail stop.

The railroad industry supported Mr. Biden's calls for legislation.

Ian Jeffries, the chief executive of the Association of American Railroads, said in a statement that no one would benefit from a rail work stop. It's the right time for Congress to act.

Four of the 12 unions representing more than 100,000 employees at large freight rail carriers have voted down the tentative agreement brokered by the Biden administration.

Martin J. Walsh, Mr. Biden's labor secretary, said in an interview that Congress would have to act if the two sides couldn't reach a deal. It was not clear if Mr. Walsh was suggesting intervention or not.

Legislation to provide federal protections for same-sex marriages will be voted on later in the day. The House will have to vote on the bill before the end of the current Congress and send it to Biden for his signature.

Lawmakers have a December deadline to fund the federal government. Part of the federal government could be shut down if there is no agreement on a temporary spending package.