WASHINGTON -- It's a deal no one in Washington claims to really like. But after weeks of negotiations, U.S. President Joe Biden and House Speaker Kevin McCarthy have struck an agreement to raise the debt ceiling and avert a potentially devastating government default.

The stakes are high for both men -- and now each will have to persuade lawmakers in their parties to vote for it. Treasury Secretary Janet Yellen said last week that the United States could run out of cash to pay the bills and default on its obligations if the debt ceiling is not raised by June 5.

The ultimate agreement, hammered out by Biden, McCarthy and a small group of their deputies, is a two-year budget deal that would essentially hold spending flat for 2024, while boosting it for defence and veterans, and capping increases at 1% for 2025. It would suspend the debt limit until January 2025, after the next presidential election. Republicans had insisted on reducing spending and had passed their own bill with much larger cuts last month.

The package would also make policy tweaks, including by adding work requirements for some food aid recipients and streamlining an environmental law that Republicans say has made it harder to build energy projects.

Takeaways from the deal, and from the negotiations that led up to it:

McCARTHY'S DELICATE BALANCING ACT

Ever since McCarthy won the House speakership on the 15th ballot in January, it was clear that the debt ceiling negotiations would be his first and perhaps biggest test.

Known more for strategy than policy, McCarthy has had a challenge that seemed almost insurmountable, with a narrow majority and a sizable group of hard-right conservatives certain to oppose anything he negotiated with Biden. And he could still find himself in the middle of a crisis if too many in his caucus revolt when the House votes on the package this week.

Through it all, the Californian has exhibited his typical laid-back vibe, projecting confidence about the bill and its success. He said Sunday that he will win a majority of Republicans on the bill and some Democrats.

In a conference call on Saturday night, McCarthy said, more than 95 per cent of the members in his conference "were overwhelmingly excited about what they see."

But some House Republicans were publicly slamming the deal, arguing it did too little to cut the deficit. Rep. Dan Bishop of North Carolina tweeted a vomit emoji, complaining that some Republicans on the call were praising the speaker for getting what he said is "almost zippo in exchange" for the debt-ceiling hike.

BIDEN'S RELUCTANT COMPROMISE

For months, Biden and his aides had a mantra: There would be no negotiation on the debt limit. But then he negotiated anyway.

It's not where Biden, a veteran of the nasty 2011 debt-limit battle that saw the nation's credit rating downgraded for the first time in history, wanted to be. But it was a likely scenario -- with a Republican-controlled House that had made it clear from the start that it would not raise the borrowing authority under a Democratic president without extracting spending curbs or other policy concessions.

There was no way Biden, who is running for re-election next year, would want a historic default on his watch.

Biden has continued to insist that he was negotiating on the budget, not the debt ceiling. But pushed by a reporter Sunday evening who noted that was precisely what Republicans were seeking in exchange for lifting the debt limit, the president seemed to break from his talking point.

"Sure, yeah," Biden said, chuckling slightly. "Can you think of an alternative?"

Now he will have to sell it to House Democrats, who must vote for it in big enough numbers to make up for defecting Republicans. Many progressive members in the House have appeared skeptical of the deal, but they remained mostly quiet over the weekend as they waited for more details.

But the deal won early praise from another key Democratic group. The New Democrat Coalition, which has roughly 100 members, praised Biden as having negotiated "a viable, bipartisan solution to end this crisis."

LONG-SOUGHT GOP POLICY

Republicans were able to win some policy changes they have sought for years, however modest, including on food aid. The bill would raise the age limit for existing work requirements in the Supplemental Nutrition Assistance Program, also known as food stamps. It would also create a new agency to develop and streamline environmental reviews that Republicans have complained about for decades.

The new work requirements for able-bodied SNAP recipients without dependents would phase in by 2025 and expire by 2030. And a provision pushed by Biden would take some vulnerable recipients -- like veterans and the homeless -- off work requirements entirely. But Republicans made clear that pushing more people to work in exchange for government benefits was a major victory for them, even if mostly symbolic.

The bill also would amend the National Environmental Policy Act and designate "a single lead agency" to develop environmental reviews, in hopes of streamlining the process.

Republicans had hoped for a much broader permitting package that would make it easier to build and develop energy projects. But Louisiana Rep. Garret Graves, a McCarthy ally who was one of the negotiators, said the bill brings "transformational changes into the permitting and environmental review process" for the first time in four decades.

SENATE QUIET, WAITING TO CLOSE

McCarthy has said the House will vote on the package Wednesday. If passed, it will then head to the Democratic-led Senate where leaders will have to get agreement from all 100 members to speed up the process and avert a default by next Monday.

The White House briefed Democratic senators Sunday and McCarthy briefed Republicans. But most senators remained quiet on the deal as they waited for the full text and to see if McCarthy can navigate it through the House.

Senate Majority Leader Chuck Schumer, D-N.Y., and Senate Republican Leader Mitch McConnell of Kentucky cut themselves out of the negotiating process early on, saying it should be a negotiation between the White House and McCarthy.

McConnell issued a statement supporting the legislation on Sunday but some in his caucus have criticized it. The two leaders will have to navigate any potential objections over the coming week as they seek to win full support to move quickly on the deal.

"With Republicans like these, who needs Democrats?" tweeted Utah Sen. Mike Lee on Saturday, aligning himself with the House Republicans who say the deal is not conservative enough.