WASHINGTON  After years of fierce lobbying and debate, Congress approved a bill on Wednesday to cover the cost of medical care for rescue workers and others who became sick from toxic fumes, dust and smoke after the 2001 attack on the World Trade Center.

The $4.3 billion bill cleared its biggest hurdle early in the afternoon when the Senate unexpectedly approved it just 12 days after Republican senators had blocked a more expensive House version from coming to the floor of the Senate for a vote.

In recent days, Republican senators had been under fire for their opposition to the legislation.

The House quickly passed the Senate bill a few hours later, as was widely expected. The vote was 206 to 60, breaking down largely along party lines. The White House said President Obama would sign the bill into law.

After the Senate vote, a celebration broke out in a room in the Capitol that was packed with emergency workers and 9/11 families, as well as the two senators from New York, Charles E. Schumer and Kirsten E. Gillibrand, and the two senators from New Jersey, Frank R. Lautenberg and Robert Menendez. The senators, all Democrats, were greeted with a huge ovation and repeated chants of “U.S.A.! U.S.A.!”