The Senate on Thursday overwhelmingly approved a $19.1 billion disaster-aid package, advancing legislation that would break a months-long impasse over federal funding for stretches of the country afflicted by natural disasters.

President Trump on Thursday evening wrote the Senate had his total support in passing the deal.

House lawmakers left town Thursday before the agreement was announced, leaving prospects for rapid passage there uncertain — though the chamber’s Democratic leaders hope to use a procedural move to quickly advance the measure Friday.

The deal, which congressional leaders presented hours before the Senate vote, would send aid to victims of Western wildfires, Midwestern flooding and hurricanes that hit the Southeast and Puerto Rico, as well as to other disaster-affected areas across the country.

The package does not include the U.S.-Mexico border funding the Trump administration requested. That demand had proved contentious, and leaving it out sidestepped a fight over immigration that had further complicated the delicate ­disaster-aid negotiations.

The Senate passed the measure 85 to 8, with bipartisan backing that followed months of finger-pointing as Democrats, Republicans and President Trump fought over funding for Puerto Rico and other issues.

Several hurdles remain for the bill to be signed into law.

Senators said Thursday afternoon that they felt confident Trump would sign the deal, and Trump saying he backed the deal could ease fears of a last-minute rejection.

Before going to Trump, the disaster package would need approval from the House, but lawmakers there left for the Memorial Day recess before the Senate voted Thursday. The House is scheduled to meet Friday for a brief “pro forma” session with few lawmakers present.

House leaders hope to advance the measure then by unanimous consent, according to a senior House Democratic aide, but a single objection from a lawmaker could sink the package until the House returns.

Before the agreement was announced, a Republican aide said conservatives opposed to new government spending could object.

Despite the remaining hurdles, prospects for passing legislation before the recess appeared much brighter than they did early Thursday, when disputes over how the border money would be spent had appeared to put a deal out of reach.

Sen. David Perdue (R-Ga.) said he and Sen. Rick Scott (R-Fla.), whose state is awaiting federal money to rebuild from Hurricane Michael, called Trump and won approval for a disaster-aid plan that left out additional immigration-related funding for the Departments of Homeland Security and Health and Human Services.

“We didn’t think we could wait any longer to get this done,” Perdue said. “Sometimes when you put too much together, you can’t get anything done. So what he did today was break through a logjam and say: ‘Look, let’s divide this and start working on border security individually or independently, and let’s get this done today.’ ”

Senate Appropriations Committee Chairman Richard C. Shelby (R-Ala.) said Congress would return to border funding in a separate measure after the recess.

Senate Minority Leader Charles E. Schumer (D-N.Y.) said the disaster deal was reached despite Trump, not because of him — noting that Trump twice blocked previous congressional accords on the legislation.

“Republicans are learning that they’re going to have to break from the president to get anything done,” Schumer said, “because the president . . . has been an obstructionist force — insisting on his own way when he knows that his own way can’t pass.”

The disaster-aid bill has been pending since last year, and the slow pace of talks has frustrated lawmakers of both parties, especially as past disaster bills have often been bipartisan and rarely featured the delays or rancor that has accompanied this one.

For much of that time, the main sticking point has been a struggle between Democrats — who pushed for more aid to Puerto Rico — and Trump, who has spent months complaining about fiscal mismanagement by the territory’s government and has drastically overstated the sums sent to the island in the wake of Hurricane Maria.

Puerto Rico, which is still trying to recover from the 2017 hurricane, will receive more than $1 billion under the package, according to a House Democratic aide. That includes $600 million in emergency funding for Puerto Rico’s food stamp program, as well as more than $300 million to help the island cover costs for infrastructure repair projects.

The White House on Thursday announced a separate program to distribute $16 billion to farmers hurt by Trump’s trade war with China.

China has placed tariffs on incoming U.S. crops such as corn and soybeans, cutting foreign demand and, consequently, domestic prices for U.S. farmers. Beijing levied the import taxes in retaliation against the Trump administration’s tariffs on hundreds of billions of dollars of Chinese goods coming into the United States.

The legislation the Senate approved Thursday also includes billions for farmers in the Southeast and other regions hit by 2018 and 2019 natural disasters, as well as close to $1 billion for repairs to military installations that suffered damage from Hurricanes Florence and Maria and other natural disasters, according to a summary provided by Shelby’s office.

Top Democratic negotiators, such as House Appropriations Committee Chairwoman Nita M. Lowey (D-N.Y.), cheered news of the disaster-aid agreement.

“Chairman Lowey is pleased that President Trump and Republicans have agreed to bipartisan, comprehensive disaster relief legislation that will meet urgent needs across the country,” Lowey spokesman Evan Hollander said Thursday. “If the Senate passes the legislation today, House Democrats support clearing it through the House as soon as possible.”

The congressional deadlock has stalled support for victims of wildfires in California and other Western states, southeastern residents hurt by hurricanes, Midwestern states that faced historic flooding earlier this year, and other areas. In Puerto Rico, food stamp payments were cut for more than 1 million residents after the program’s emergency funding expired in March.

In recent talks, negotiators had closed the gap on Puerto Rico funding, only to see a new dispute spring up over the Trump administration’s demand for $4.5 billion in new border funding.

While lawmakers from both parties broadly agree border agencies need more funding to address the influx of individuals and families arriving from Central America, Democrats and the White House are split over how the funding should be used. Democrats demanded restrictions to prevent it from going to certain detention and enforcement programs they oppose, while the Trump administration sought more leeway.

Before the agreement was announced Thursday, House Speaker Nancy Pelosi (D-Calif.) had urged the Senate to pass her chamber’s version of the disaster bill, a package that won the support of all of the chamber’s Democrats and 34 Republicans.

She also provided a preview of a fight over border spending that will be waiting for lawmakers when they return in June.

Addressing reporters at a news conference, the House leader declared the Trump administration’s conditions for border funding “unacceptable.”

A previous version of this story gave the incorrect title for Senate Minority Leader Charles E. Schumer (D-N.Y.).

Erica Werner, Damian Paletta and Felicia Sonmez contributed to this report.