Congress completed work on a two-year budget after an early Friday morning vote to approve the  deal that would increase spending limits and avert a damaging default, essentially ending the budgetary battles that have defined President Obama’s relationship with Congress in recent years.

The legislation was approved by the Senate in a vote of 64-35 just before 3 a.m. on Friday after overcoming objections from conservative senators, including presidential candidates Rand Paul (R-Ky.) and Ted Cruz (R-Tex.). Obama has until Nov. 3 to sign the agreement before the debt-limit deadline set by the Treasury Department.

Obama released a statement Friday morning saying he would sign the bill “as soon as it reaches my desk.”

“I applaud the Democrats and Republicans who came together this morning to pass a responsible, long-term budget agreement that reflects our values, grows our economy and creates jobs,” he said in the statement. “This agreement is a reminder that Washington can still choose to help, rather than hinder, America’s progress.”

The agreement, unveiled earlier this week, is the result of tightly held negotiations between congressional leaders in both parties and the White House to increase spending and suspend the debt ceiling through March 2017 in order to avoid default. The deal will lift the so-called sequester spending caps and increase discretionary spending by about $80 billion over two years, an amount that will be split equally between defense and domestic programs.

To offset this cost, negotiators tapped a number of sources, including making changes to Medicare and Social Security, auctioning off government-controlled wireless spectrum, selling crude oil from the Strategic Petroleum Reserve and tightening tax rules for business partnerships.

In addition, the legislation will limit a historic premium increase for some Medicare Part B beneficiaries, set to go into effect next year, for services like hospital care and doctor visits.

The agreement also will prevent a potential 20 percent across-the-board cut to Social Security Disability Insurance benefits scheduled to take place next year, by transferring resources from the main Social Security fund and making changes to the program. The cost-saving revisions include allowing some recipients who can still work to receive partial payments while earning outside income, and expanding a program requiring a second medical expert to weigh in on whether an applicant is legitimately disabled.

[House Republican leaders push for floor vote on budget despite conservative objections]

Once the bill is signed into law, the Appropriations Committees will begin the process of writing an omnibus bill that will determine how the funds will be spent. That process is expected to take about a month and could be complicated if Republicans try to attach controversial provisions, like defunding Planned Parenthood, to the legislation.

Democrats have vowed to block any “poison-pill” riders, which could create another spending standoff in December.

Senators were resigned to the early-morning vote on Friday, after it became clear that Senate leaders would only be able to cut off debate and move on final passage after midnight. Some said they anticipated the rare pre-dawn vote would give disgruntled colleagues less incentive to give floor speeches denouncing the agreement.

“Maybe they would decide it would be better to speak when people are actually paying attention,” said Senate Majority Whip John Cornyn (R-Tex.).

Senate rules allowed for each senator to speak for one hour after the first procedural vote but only Paul chose to use his time. He criticized Senate leaders for caving into demands from Democrats to negotiate on spending rather than using the upcoming debt limit deadline to force President Obama to make spending cuts.

“This is exactly the time we should be using the leverage of the debt ceiling,” Paul said just before 1 a.m. on Friday.

[Rand Paul may hate the budget deal but he can’t stop it now]

The final agreement sped through Congress after former House Speaker John A. Boehner (R-Ohio) formally announced the bipartisan agreement on Monday at a closed-door meeting with House Republicans. There was pressure to strike a deal soon because of two approaching deadlines — one fiscal, one political.

The Treasury Department has warned that the government will run out of borrowing authority by Nov. 3 and a failure to raise the debt ceiling could lead to an economy rattling default.

The second deadline was the end of this month, when Boehner planned to step down from Congress after too many fights with a band of conservatives in his party.

Boehner said he wanted to “clean out the barn” before handing over the gavel, rather than leave his successor with a pile of messy budget business to handle just as they assumed the job. On Thursday, the House elected Rep. Paul D. Ryan (R-Wis.) speaker, a day after the House passed the budget agreement on a 266 to 167, which served as a coda to Boehner’s tenure as speaker.

Conservatives in both chambers criticized the deal both because it was hatched behind closed doors rather than through the committee process and because they argued it is bad policy.

Many complained that the provisions in the bill that are used to offset the cost of the new spending are gimmicks or promise savings in the future for money the government will spend immediately.

Cruz criticized leaders for negotiating behind closed doors and for agreeing to President Obama’s requests for additional spending.

“This wasn’t a slapdash on a Post-it note last night,” Cruz said. “This represents days or weeks or months of negotiations. This represents the Cartel in all of its glory because this is the combined work product of John Boehner and Nancy Pelosi and Mitch McConnell and Harry Reid.”

This story has been updated.