A federal bankruptcy judge approved a major debt restructuring plan for Puerto Rico in the first deal of its kind for the U.S. territory since the island’s government declared nearly four years ago that it was unable to repay its public debt.

The agreement involves more than $17 billion worth of government bonds backed by a sales-and-use tax, with officials saying it will help the government save an average of $456 million a year in debt service. The deal allows Puerto Rico to cut its sales-tax-backed debt by 32 percent but requires the government to pay $32 billion in the next 40 years as part of the restructuring.