WASHINGTON — The American tax code was rewritten in a few hours on Friday night, as Republicans passed a hastily prepared bill that slashes corporate tax rates and has far murkier implications for the American middle class.

The 479-page bill was released to senators less than 9 hours before they voted 51 to 49 to pass the bill, with 1 Republican voting against it. Senators passed the tax bill shortly before 2 a.m. EST.

Applause rang out in the Senate chamber as Republicans celebrated passage of their bill. Vice President Mike Pence presided over the vote, announcing its passage. Before the vote ended, Democrats left the Senate chamber.

The core of the bill remained the same as its previous version; it is still expected to add $1 trillion in debt to the federal government while cutting the corporate tax rate from 35% to 20%. Republicans have promised that tax cut will create jobs, though several of them had difficulty specifying how on Thursday.

Most Americans will see a tax cut in 2018. However, a repeal of the Affordable Care Act’s requirement that citizens purchase insurance is projected to increase middle class taxes over time.

Dozens of additions were made to the bill well into Friday night. Sen. Dick Durbin (D-Ill.) held up a page of the legislation on the Senate floor that had hand-written notes in the margin. Sharing a picture of the page, Durbin tweeted: “Can anyone else read this?”

Sens. Susan Collins (R-Maine), Ron Johnson (R-Wisc.) and Jeff Flake (R-Ariz.) voted for the bill, which Sen. Bob Corker (R-Tenn.) had announced his opposition to the bill before the final vote, saying it grew federal debt unsustainably.

The bill now heads to the House, and Republicans there can either try to pass the Senate’s bill outright, or enter a conference committee. They’ve already promised to do the latter, which means the Senate and House will have to vote again on a compromise bill.

Still, the Senate’s approval puts the plan one step closer to becoming law.

The bill’s passage was fraught with drama. Initially, it looked like Senate Republicans were going to pass the bill on Thursday. However, on Thursday evening a handful of deficit hawks — including Corker and Flake — objected to a non-partisan report that showed the plan would not be paid for by economic growth Republicans promised.

In the end, Flake ended up supporting the tax bill even though his deficit concerns were not addressed, as he said he received a commitment from Republican leaders and the White House to protect Deferred Action for Childhood Arrivals recipients, or individuals who entered the U.S. as minors and had remained in the country illegally.

Before voting on the final bill, senators voted on a raft of proposed amendments to the bill. Sen. Marco Rubio (R-Fla.) proposed an amendment to expand the child tax credit to benefit Americans who do not pay income tax. It would have increased the corporate tax rate in the bill to nearly 21%. The amendment failed, as dozens of Democrats voted against it to avoid giving Republicans any mark of bipartisanship on their bill.

Immediately before taking the final vote on the tax bill, four Republicans sided with Democrats to remove a last-minute provision added to the tax legislation on Friday to benefit a small, private unviersity. Sens. Collins, Lisa Murkowski (R-Alaska), John Kennedy (R-La.) and Deborah Fischer (R-Neb.) voted with all the Democrats to remove an addition to the bill to exempt Hillsdale College from paying an excise tax.

The run-up to the vote saw Republican and Democratic senators rehashing their top talking points from the past few weeks.

“Historians will look back on Dec. 1, 2017,” Sen. Bernie Sanders (I-Vt.) said. “They will conclude this was one of the great robberies — one of the great criminal activities ... because the Treasury is being looted.”