Senate and House leaders announced on Sunday that they had struck an overarching agreement on 2024 government funding, but it was not clear whether they would be able to cement the deal and pass it into law in time to avert a partial government shutdown in less than two weeks.

After weeks of negotiations and on the eve of Congress returning from its holiday break, top Senate and House members said they had agreed to set the total amount of spending at nearly $1.66 trillion, bringing funding in line with the deal struck last year between President Biden and then-Speaker Kevin McCarthy that met with vehement conservative opposition.

The agreement includes an increase in Pentagon spending to $886.3 billion and holds nondefense funding essentially flat at $772.7 billion, including $69 billion of added money agreed to through a handshake deal between Mr. McCarthy and the White House. That additional spending is offset by speeding up $10 billion in cuts to I.R.S. enforcement and clawing back $6 billion in unspent Covid dollars and other emergency funds. Officials said the agreement did not include an additional $14 billion sought by the Republican and Democratic appropriators in the Senate to beef up both domestic and military spending.

“By securing the $772.7 billion for nondefense discretionary funding, we can protect key domestic priorities like veterans benefits, health care and nutrition assistance from the draconian cuts sought by right-wing extremists,” Senator Chuck Schumer, Democrat of New York and the majority leader, and Representative Hakeem Jeffries of New York, the House Democratic leader, said in a joint statement.

In briefing his colleagues Sunday on the framework he negotiated, Mr. Schumer called it a “good deal for Democrats and the country,” and he and Mr. Jeffries said Congress would need to take a bipartisan approach to “avoid a costly and disruptive shutdown.”

In a letter to his colleagues, Speaker Mike Johnson emphasized the spending reductions that Republicans had secured, notably the extra $10 billion from the I.R.S., and said that the “result is real savings to American taxpayers and real reductions in the federal bureaucracy.”

While calling the agreement the best spending deal Republicans had secured in years, Mr. Johnson acknowledged that “these final spending levels will not satisfy everyone, and they do not cut as much spending as many of us would like.”

President Biden noted that the deal “provides a path” to funding the government without deep cuts.

“Congressional Republicans must do their job, stop threatening to shut down the government, and fulfill their basic responsibility to fund critical domestic and national security priorities, including my supplemental request” for Ukraine and Israel, he said in a statement.

Congress faces its initial deadline for passing four spending bills on Jan. 19, and getting an overall deal on total funding is just the first step in avoiding a shutdown. A second deadline for finishing the remaining eight appropriations bills, including the one covering the Pentagon, looms on Feb. 2. Finishing the job could prove a daunting task. Lawmakers returning to Washington also face big decisions on the emergency spending package for Ukraine and Israel, which Republicans have refused to consider without strict new immigration policies to stem the flow of migrants into the United States.

“The bigger problem that I see is, how does a bill that has to combine four separate bills pass both chambers and become law in less than two weeks’ time?” said Senator Susan Collins of Maine, the top Republican on the Senate spending panel. “This is not going to be easy, to give the understatement of 2024.”

Senator Patty Murray, Democrat of Washington and chair of the Appropriations Committee, said on Sunday that she “will be working with my colleagues around the clock in the coming days to prevent a needless shutdown.”

At the same time, Mr. Johnson is under increasing pressure from some ultraconservatives in the House to reject any spending agreement unless Mr. Biden and congressional Democrats agree to stiff new controls to restrict the flow of migrants across the southern border. Senate Republicans and Democrats have reported progress toward a deal to impose new immigration restrictions, which could come as soon as this week, but House Republicans have signaled they want more severe measures.

Senate and House Democrats are insisting that the forthcoming spending bills be free of policy dictates that House Republicans have sought to scatter through their bills aimed at limiting abortion rights and reining in what they consider a “woke” and weaponized federal bureaucracy. But Mr. Johnson on Sunday said he intended to “fight for the important policy riders” in the House measures.

The new spending agreement allows leaders of the House and Senate Appropriations committees to set the funding levels for the dozen individual spending bills for the federal government. To put it into force, they would have to come to terms on the four set to expire in mid-January — covering veterans programs, transportation and housing, energy and water projects, and agriculture and food and drug regulation — and move them through the House and Senate and to Mr. Biden’s desk.

Congress could potentially avert a partial shutdown by passing another short-term funding bill if lawmakers ran out of time. But Mr. Johnson explicitly ruled out another temporary measure when he pushed through the current funding with Democratic help in November. Given his shrinking majority in the House resulting from resignations and illnesses, he will likely need substantial Democratic votes to push through any spending package, providing House Democrats with significant leverage in shaping the measures.

Mr. Johnson sought to play down conservative demands to tie governmentwide spending to the border situation during an appearance on Sunday on CBS’s “Face the Nation.”

But Representative Chip Roy, the Texas Republican who was campaigning in Iowa with Gov. Ron DeSantis of Florida over the weekend, suggested he would not let the issue drop and on Sunday posted the hashtag #NoSecurityNoFunding” on social media.

“I got some text messages from — I won’t say who — one of the Republican leaders today, saying how my tactics and my position on the southern border are not helpful, how they’re ‘ticking off’ some of my colleagues,” he told a crowd in Ankeny. “I said, ‘Well, it’s not gonna be the first time and it’s not the last.’”

Mr. Roy said he was “a hard, violent no on caps-busting spending and not securing the border, and that’s where it seems like we’re heading.”

Should Congress fail to pass all 12 spending bills, it would prompt automatic, across-the-board cuts of 1 percent, a fallback included in the legislation to suspend the debt limit that was passed last June to avert a federal default. Mr. Johnson and other House Republicans have warmed to the possibility of extending the stopgap spending bill through the end of the fiscal year on Sept. 30 and taking the fiscal hit as an alternative to passing the spending bills.

That approach has drawn fierce resistance from both Republicans and Democrats in the Senate, the White House and House Democrats who say that it would gut domestic programs and pare Pentagon spending and should be avoided at all costs.

If the effort to pass the spending bills stalls, Congress could also pass a yearlong continuation of current funding and vote to eliminate the 1 percent cut. That approach would wipe out any policy and funding changes made in the pending spending bills, a scenario that those who wrote the measures would like to avoid. Ms. Collins said that approach would eliminate a 30 percent boost in shipbuilding funds and leave scores of new Pentagon programs without money.

Negotiators have been predicting that they are close to a deal on strict new border provisions, though they have not yet agreed on every issue under debate. The last sticking points include a dispute over how and when migrants should be paroled into the country while awaiting their immigration court dates — a practice that the G.O.P. wants to curtail and replace with the Trump-era policy of keeping migrants in Mexico if detention centers on the U.S. side of the border are oversubscribed.

“We’re hoping to get text out by later on this week,” Senator James Lankford, Republican of Oklahoma, said on “Fox News Sunday,” noting that negotiators wanted to give lawmakers time to closely inspect the bill before a potential vote and to ensure that “nobody’s going to be jammed in this process.”

Senate Democrats and Republicans are expected to be briefed on an outline of the emerging deal during their party policy lunches on Tuesday, and Republicans are planning a special conference meeting on Wednesday to discuss the details further.

Karoun Demirjian contributed reporting from Washington, and Catie Edmondson from Ankeny, Iowa.