From the increase in domestic spending, Mr. Schumer said the deal includes $20 billion for infrastructure, $6 billion for the opioid crisis and mental health, $5.8 billion for child care and $4 billion for Veterans Affairs hospitals and clinics. It also includes disaster relief for areas hit by last year’s hurricanes and wildfires.
The deal also includes $4.9 billion — two years of full federal funding — for Medicaid in Puerto Rico and the United States Virgin Islands, helping to avoid a looming Medicaid shortfall. There is additional money to repair infrastructure, hospital and community health centers severely damaged by Hurricanes Irma and Maria.
The relief aid also includes $28 billion in community development block grants, including $11 billion for Puerto Rico, with $2 billion of that going to repair the power grid. About 30 percent of Puerto Ricans — more than 400,000 customers — still don’t have electricity more than four months after Hurricane Maria. Puerto Rico requested $94.4 billion in aid after the storm.
The agreement includes an additional four-year extension of funding for the Children’s Health Insurance Program, on top of the six-year extension that Congress approved last month, according to Mr. Schumer.
“I hope we can build on this bipartisan momentum and make 2018 a year of significant achievement for Congress, for our constituents and for the country that we all love,” Mr. McConnell said.
Mr. Schumer was similarly effusive.
“After month of legislative logjams, this budget deal is a genuine breakthrough,” he said. “After months of fiscal brinkmanship, this budget deal is the first real sprout of bipartisanship.”
Defense Secretary Jim Mattis and White House Press Secretary Sarah Huckabee Sanders embraced the deal, boosting its chances in the House, where conservatives were cool to it, if not hostile.
The deal did also spark opposition from the leader of House Democrats, Representative Nancy Pelosi, who said she could not agree to any budget deal that was not accompanied by a debate over legislation to protect the fate of young immigrants brought to the country illegally as children, known as Dreamers.
“Without that commitment from Speaker Ryan, comparable to the commitment from Leader McConnell, this package does not have my support, nor does it have the support of a large number of members of our caucus,” Ms. Pelosi said on the House floor, where she spoke at length about Dreamers on Wednesday.
She was referring to a promise by Mr. McConnell to begin debate on immigration soon, a commitment not matched by Speaker Paul D. Ryan of Wisconsin.
But Mr. Ryan did not rush to offer the assurance that Ms. Pelosi sought.
“Speaker Ryan has already repeatedly stated we intend to do a DACA and immigration reform bill — one that the president supports,” a spokeswoman for Mr. Ryan, AshLee Strong, said, referring to the Obama-era program that shields Dreamers from deportation, Deferred Action for Childhood Arrivals, or DACA.
The budget deal would be paired with a stopgap spending measure that would keep federal agencies open past Thursday, when the current funding measure is set to expire.
It was not immediately clear if enough Democrats would oppose the bill to imperil its passage in the House, given the likely opposition from at least some fiscal conservatives. If lawmakers cannot pass a temporary funding measure by the end of Thursday — either by itself or tied to a budget pact — the government would shut down for the second time this year.
The budget agreement would also negate the president’s demands to broadly reorder government with deep cuts to domestic programs like environmental protection, foreign aid, and health research that were to offset large increases in military spending. Mr. Trump is to release his second budget request on Monday, but the deal — sealed by members of his own party — would effectively render many of his demands null and void.
If the deal passes, lawmakers would put together a long-term spending package over the coming weeks that would fund the government through September, granting a measure of peace to Washington as attention turns to the midterm elections in November. By setting overall spending levels through September 2019, the deal would ease passage of spending bills in the next fiscal year as well.
Only on Tuesday, President Trump was trying to engage in fiscal brinkmanship, threatening another government shutdown if his hard-line demands on immigration were not met.
“I’d love to see a shutdown if we don’t get this stuff taken care of,” Mr. Trump said at a meeting with lawmakers and law enforcement officials to discuss gang violence. “If we have to shut it down because the Democrats don’t want safety,” he added, “then shut it down.”
But budget negotiators seemed to pay him little heed.
“While President Trump threatens shutdowns and stalemates, congressional leaders have done the hard work of finding compromise and consensus,” Mr. Schumer said. He added, “At the end of the day, I believe we have reached a budget deal that neither side loves, but both sides can be proud of.”
The deal had eluded negotiators for months, as it became intertwined with delicate negotiations on other matters, particularly the contentious issue of immigration.
But after last month’s three-day government shutdown, Senate Democrats were willing to finalize a budget deal separately from the debate over immigration.
The deal also makes for another lonely day for lawmakers concerned about the budget deficit, which was already expected to reach $1 trillion in the next fiscal year, according to the Committee for a Responsible Federal Budget, a fiscal watchdog group.
The sweeping tax overhaul approved by Congress in December is projected to add $1.5 trillion to the deficit over a decade, and the budget agreement will balloon the deficit even further.
The deal quickly drew scorn from conservative groups angered by the big increase in spending.
Jason Pye, the vice president of legislative affairs for FreedomWorks, said the deal “isn’t just fiscally irresponsible, it’s an abomination.”
“No one in Congress who claims that they’re a deficit hawk or a fiscal conservative can justifiably vote for this deal,” he said.
Jenny Beth Martin, chairwoman of the Tea Party Patriots Citizens Fund, also assailed the deal, citing the size of the national debt.
“When will our so-called ‘Republican leaders’ ever learn to stick by their promises and previous statements?” she asked. “Republicans in Congress should step away from Chuck Schumer’s negotiating table and work to pass a budget that balances by making tough choices and eliminates our more than $20 trillion in debt. Anything less would be an abandonment of their promises to the American people.”