The loophole allowed for Swiss banking giant UBS and other banks to underwrite specific Puerto Rico bonds and then sell them directly into bond funds that were sold only to island residents, a CNBC investigation , published in December, found.

This exemption from the so-called Investment Company Act of 1940 also allowed funds in Puerto Rico to skirt leverage standards and certain affiliated party transactions that apply to funds operating in the U.S.

The provision ends a 78-year-old legislative loophole that allowed subsidiaries of global banking institutions that operated in U.S. territories, like Puerto Rico, to do certain types of financial transactions that are legally barred stateside.

Tucked inside legislation that passed the House of Representatives Tuesday night — a larger bill largely focused on rolling back Dodd-Frank banking regulation — is a provision that creates greater oversight of brokerage firms operating in U.S. territories.

U.S. lawmakers closed a long-standing legal loophole that helped spark a financial crisis in Puerto Rico that has decimated the savings of thousands of residents.

The funds, which were not registered with the SEC, were highly levered and concentrated largely in Puerto Rico bonds, which became practically worthless in recent years. The residents who bought them lost billions of dollars in savings.

The legislation passed Tuesday repeals the exemption to ensure that financial institutions that operate in all U.S. territories, including Puerto Rico and the U.S. Virgin Islands, have to abide by the same rules as their stateside counterparts. Funds issued and sold to investors by institutions in Puerto Rico will now need to be registered with the SEC.

CNBC's investigation prompted Rep. Nydia Velázquez (D-N.Y.) to call for a congressional hearing to investigate the marketing and sales practices of investment companies operating in Puerto Rico. Her office is expecting that the passage of Tuesday's bill will negate the need for such a hearing.

Velázquez, a senior member of the House Financial Services Committee, had tried three times before, in 2015, 2016 and last year, to close the loophole. But her prior bills, which weren't part of a bigger legislative package, failed to pass.

When Congress first enacted the Investment Company Act of 1940, it was deemed too expensive for regulators with the SEC to travel to U.S. territories — which then also included Alaska and Hawaii, in addition to Puerto Rico and the U.S. Virgin Islands.

Since then, both Alaska and Hawaii have become states, air travel to and from Puerto Rico has become less expensive and a large portion of financial activity takes place electronically. That makes it far easier for regulators to patrol financial activities in U.S. territories than it was 78 years ago, Rep. Velázquez has argued.

The bill, called the "Economic Growth, Regulatory Relief and Consumer Protection Act, passed on Tuesday.

Velazquez said she voted no on it for other reasons. For example, the bill rolls back many protections for bank customers, including preventing discrimination against minorities in mortgage lending. It also raises the threshold for a bank to be considered systemically important to $250 billion in assets. It was seen as favorable to medium-sized U.S. banks by loosening some of the current rules.

"On balance, these are poor choices that, in my view, heighten the risk of improper financial activities similar to those that precipitated the 2008 financial crisis," Velazquez said in a statement.

On-island financial institutions will have three years to comply with the new rules, assuming they get signed into law. The SEC has to option to grant an additional three years, if warranted.

"This bill will put Puerto Rico's mutual fund industry in regulatory parity with the Mainland and, at last, bring to an end decades of exploitation of Puerto Rican investors," Velázquez said in a written statement. "I am heartened, at least, that by passing my legislation, as part of this larger package, we will no longer hear of the people of Puerto Rico being swindled out of their nest eggs due to an antiquated loophole in federal investment law."