IN RECENT years it has usually been the House of Representatives which has waited until the last moment to avert an economic catastrophe, a government shutdown or a default. This week it was the Senate’s turn. On June 29th the upper house passed a bill, already approved by the House and backed by the president, allowing Puerto Rico to restructure its debts, two days before the Caribbean territory was set to default on a $2 billion payment.

Default was the only option left for the island. The government does not have the money to pay the bill, according to Puerto Rico’s governor, Alejandro García Padilla. Nobody sane would lend it to them. But default was not itself the main worry; few will shed tears for the territory’s creditors. The real problem is that investors in Puerto Rican debt have filed lawsuits arguing that the island must pay them before buying things like fuel for police cars and medicine for hospitals. A concurring judge could kill-off the island’s public services, which the debt crisis has already wounded badly. For example, the neonatal unit in the island’s largest hospital, which Jack Lew, the Treasury secretary, visited in May, can only get hold of supplies if it pays cash-on-delivery. “The government of Puerto Rico is about to collapse” warned Pedro Pierluisi, the territory’s non-voting congressman, on June 23rd.

The bill halts the lawsuits until at least February 2017. In the meantime, it permits a debt restructuring, hitherto impossible partly because Puerto Rico is a mere territory (were it a state, its public utilities, which bear much of its debt, could have declared bankruptcy). A two-thirds majority of bondholders will be enough to force all to accept a reduction in what they are owed. A “financial oversight board” will chaperone the island through the process and also monitor its budget, rewriting it if that is deemed necessary.

Crucially, the bill covers the so-called “general obligation” bonds which the Puerto Rican constitution says must be paid prior to any other spending. The island is used to avoiding its own rules; a hole in the constitution’s balanced-budget requirement was one of the factors which caused the fiscal crisis in the first place.

In the Senate, the cross-party bill faced more opposition from the left than it had in the House, where over four in five Democrats backed it on June 9th. Just under a third of Democratic senators, including Bernie Sanders, who has yet to end his campaign formally, voted against the deal. They objected to some of the small print, which loosens minimum-wage and overtime regulations, and the rules for appointing members to the oversight board.

Some of these objections are flimsy, especially given the urgent need for the bill. Take the minimum-wage. Currently, firms can pay under-20s $4.25 an hour, rather than the federal minimum of $7.25, for the first 90 days of their employment. The bill temporarily broadens the eligibility for this exemption in Puerto Rico to include under-25s—hardly the stuff of laissez-faire dreams. The governor will have the power effectively to drop the 90-day limit for four years, but Mr García Padilla says that will never happen. In any case, a lower minimum wage would probably benefit Puerto Rico, where the median hourly wage is just $9.61, compared to $17.40 nationally.