The House voted overwhelmingly Thursday to approve a long-awaited rescue package for Puerto Rico that could allow the fiscally troubled U.S. territory to restructure the $72 billion it owes bondholders in exchange for new federal oversight over its locally elected government.

The bipartisan 297-to-127 vote followed months of intense negotiations between House Republican leaders, Democratic lawmakers and the Obama administration. Those talks were punctuated by a high-dollar public relations campaign aimed at derailing any deal that could force bondholders to swallow significant losses.

Thursday’s House vote came ahead of a crucial July 1 deadline, when the territory is poised to default on $2 billion in bond payments. The Senate, however, has yet to act.

Lead sponsor Rep. Sean Duffy (R-Wis.) said that unless the rescue bill becomes law, “the Puerto Rican government is likely to collapse, participants in public pension plans will be terribly damaged, and almost all bondholders could lose their investments.

“Absent this bill,” he said, “almost nobody wins and nearly everybody loses.”

The territorial government and the Obama administration have both warned of a brewing humanitarian crisis if the island’s mounting public debt is not eased. Already, debt service consumes more than one-third of annual government revenues, which has threatened into the island’s ability to address the education, safety and health of the public — including the serious threat posed by the Zika virus.

On Tuesday, the island’s only airborne ambulance service said it was suspending its services after territorial officials declined to pay a $4.4 million bill, according to an Associated Press report.

Republicans, who pointed to the bill’s potential to upend bond markets and set a precedent for future fiscal interventions, have been most skeptical of the rescue legislation in recent months. But much of the last-ditch lobbying was aimed at Democrats influenced by a rising tide of popular sentiment on the island against the bill, known as the Puerto Rico Oversight, Management and Economic Stability Act, or PROMESA, after the Spanish word for “promise.”

The oversight board established under the bill would have broad powers to manage the territory’s fiscal affairs, including the power to enforce balanced budgets though asset sales and employee layoffs. The seven members would be selected by President Obama from lists drawn up by congressional leaders, most of them Republicans.

The raging debate in Puerto Rico was reflected in the gubernatorial primary elections held there Sunday, in which Pedro Pierluisi, the island’s nonvoting House representative who supports PROMESA, lost to Ricardo Rosselló Nevares, an outspoken opponent of the bill, in his bid for the New Progressive Party nomination.

That sentiment has filtered up to Washington, where groups advocating for the island’s interests have redoubled their objections to the bill in tandem with labor unions wary that $46 billion in unfunded public-employee pension obligations might be restructured alongside the bond debt.

In a fiery speech on the House floor, opponent Rep. Luis Gutiérrez (D-Ill.) compared the proposed oversight board to the state-appointed fiscal manager in Flint, Mich., who made the disastrous decision to change the city’s water supply.

“If you give power to a control board unelected and unsupervised by anyone here, be careful,” he said. “Remember Flint. Remember the poisoning of the people and what the control board did there. That is exactly what we should suspect will happen.”

The Obama administration made a last-ditch effort to convince Democrats this week, inviting Gutierrez and other influential Democratic lawmakers to the White House for a Tuesday meeting with President Obama and Treasury Secretary Jacob Lew. And on Wednesday morning, Lew visited a House Democratic Caucus meeting to urge support for the rescue bill.

House Minority Leader Nancy Pelosi (D-Calif.) played a leading role in crafting the compromise and convincing her colleagues to support the bill. More Democrats than Republicans ending up voting for it Thursday.

“Is it a perfect bill? It is not. We would prefer that the board had a different makeup and perhaps different responsibilities and powers,” Rep. Steny Hoyer (D-Md.), the Democratic whip, said this week. “But having said all that … in a world of alternatives, this is an alternative we need to take.”

Rep. Rob Bishop (R-Utah), chairman of the House Natural Resources Committee and a leading GOP proponent of the rescue bill, said Wednesday that he was not concerned by the results of Sunday’s election or the new objections arising on the island.

“If you were running for governor of Puerto Rico, you would bad-mouth PROMESA,” he said. “But you would also, if you’re running for governor, realize there has to be a solution. This is the ideal solution. … You can also blame the board for all the bad decisions from here on in. It’s brilliant for a governor candidate’s politics.”

Bishop was among those targeted by the shadowy campaign against the legislation that aired TV ads referring to the bill as a “bailout,” though the bill would not send any federal taxpayer funds to the island.

One influential conservative advocacy group, Heritage Action for America, announced it opposes PROMESA and plans to include the vote on its legislative scorecard. But two major organizations of conservative House members — the Republican Study Committee and the House Freedom Caucus — did not take positions on the bill.

A cadre of House conservatives remained sharply opposed to the bill, but House Speaker Paul D. Ryan (R-Wis.) made a major push to sell the bill to Republicans, culminating with a forceful plea on the House floor Thursday.

“This bill prevents a bailout; that’s the entire point,” he said. “If we do not pass this bill, then there is much more likely going to be a bailout, because there is no other choice.”

Ryan racked up a major legislative achievement with the passage of PROMESA, a politically thorny and technically complex bill that also represents the first significant policy initiative that he has both launched and shepherded through the House since becoming speaker in October.

The White House issued a statement Thursday strongly backing the bill in spite the inclusion of provisions — including a potential suspension of the minimum wage and overtime rules — that Democrats largely oppose: “Failing to act now will result in an economic and humanitarian crisis far beyond what Puerto Rico is already facing today.” Also backing the bill hours before passage were two influential Democrats of Puerto Rican heritage, Reps. Jose Serrano and Nydia Velazquez of New York.

Opposing the bill were 103 Republicans and 24 Democrats.

The bill now faces an uncertain timetable in the Senate. Sen. John Cornyn (R-Texas), the majority whip, suggested this week that the bill might receive swift floor consideration, but senators opposed to the bill could delay passage until close to or after the July 1 deadline. Key Senate leaders of both parties have refrained from taking a firm position on the House bill.

PROMESA includes a stay of litigation to give the oversight board time to start its work and to give creditors an opportunity to negotiate voluntary settlements. Should Puerto Rico default on July 1 without the stay in place, creditors would likely to rush to courthouses, kicking off a litigation spree that the territorial government and many bondholders are hoping to avoid.

The bill would instead set up a process that would allow for an orderly restructuring of the island’s debts in a process akin to bankruptcy. But how quickly that happens will depend on how soon the law is passed and the board is appointed — and on who is appointed to it.

“A lot of what’s going to happen is based on who’s appointed by the various congressional leaders and the president,” said Greg Clark, who heads municipal research for Debtwire, a firm that conducts bond-market analysis. “I think you have the right people on the board and have a good staff, you’ll have a good outcome.”