U.S. lawmakers on Friday were close to finalizing a historic overhaul of financial regulations after hammering out agreements on the most contentious sticking points of the bill.

As a marathon negotiating session passed the 19-hour mark, Democrats agreed to a compromise that would allow banks to retain the bulk of their lucrative swaps-dealing operations, resolving a standoff that had threatened to scuttle the entire effort.

They had earlier agreed on a separate measure that would limit banks' risky trading activities, with some exceptions.

With the most controversial aspects resolved, lawmakers looked certain to finish a final version of the most sweeping rewrite of the Wall Street rulebook since the 1930s. The bill would boost consumer protection, tighten financial regulations and reduce the industry's profits by billions of dollars.

In a wood-paneled room on Capitol Hill, financial regulators and Obama administration officials huddled with tired lawmakers who chomped on chocolate bars to stay sharp as they weighed billion-dollar decisions.

I've been here long enough, said Democratic Representative Collin Peterson, who offered the derivatives compromise. We need to get this done.

As dawn approached, bleary lawmakers yielded the microphones to staffers to debate the bill's finer points.

Lawmakers had yet to resolve whether financial firms would have to pay a tax of roughly $19 billion, spread out over several years, to cover the cost of the bill.

Democrats face enormous pressure to complete work on the bill in the coming hours, before Obama discusses recovery and reform with leaders of other economic powers at the Group of 20 meeting in Canada.

Around midnight, they approved a modified version of the so-called Volcker rule, which would curb risky trading and some investment activity by banks.

It would give regulators little wiggle room to waive the trading ban but would also allow banks to invest up to 3 percent of their tangible equity in hedge funds and private equity funds.

On Wall Street, the prospect of tough new rules sent U.S. bank stocks lower on Thursday, helping to pull down the overall market. The KBW banks index closed down 2.2 percent.

SHIELD FROM RISKY TRADING

Both the Volcker rule and the swaps-dealing proposal would shield banks' taxpayer-backed assets from the risky trading activity that led to the 2007-2009 financial crisis and massive taxpayer bailouts of Wall Street.

The reform bill -- nearly 2,000 pages in all -- aims to avoid a repeat of the crisis that plunged the global economy into a deep recession and led to taxpayer bailouts of troubled banks.

One major element would tame the $615 trillion derivatives market by forcing much trading activity onto exchanges and clearinghouses. Over-the-counter derivatives worsened the financial crisis and led to a $182 billion taxpayer bailout of insurance giant AIG.

Lawmakers had deadlocked over one part of the derivatives crackdown that would have forced banks to spin off their lucrative swaps-dealing operations into separately capitalized affiliates.

Dozens of Democrats in the House of Representatives said that would force trading overseas, and threatened to vote against the bill if it included the provision.

Obama administration officials huddled for hours with the measure's sponsor, Democratic Senator Blanche Lincoln, and other lawmakers to work out a compromise.

The final agreement allows banks to stay involved in foreign-exchange and interest-rate swaps dealing, which account for the bulk of the $615 over-the-counter market. They also could participate in gold and silver swaps and derivatives designed to hedge their own risk.

They would need to spin off dealing operations that handle agricultural, energy and metal swaps, equity swaps, and uncleared credit default swaps.

Passage of the bill would give Democrats an important legislative victory, alongside healthcare reform, ahead of congressional elections in November.

It would also give Obama a blueprint for other countries at the G20 meeting as they strive to coordinate their reform efforts.

As the global economy emerges from the financial crisis of 2007-2009, Europe's efforts to present a united front on regulation hit a roadblock on Thursday when lawmakers and diplomats failed to agree on new hedge fund rules.

Wall Street lobbyists have been unable to kill the overhaul as Democrats ride a wave of public disgust at bank bailouts and bonuses. But Democrats have to balance their desire to crack down on Wall Street with the need to retain the votes of moderates from both parties.

Democrats hope Obama can sign the reforms into law by July 4 but the final package must first win approval in the House and Senate.

One Senate moderate, Republican Scott Brown, was at the center of efforts to carve out exemptions to the Volcker rule, for mutual funds, insurers and banks in his home state of Massachusetts.

The panel also resolved other issues which will have far-reaching implications for the financial industry.

They agreed to tighten bank capital rules to help them ride out future crises.

Banks would have five years to meet the rules, which force them to exclude some riskier securities from core capital. Banks with less than $15 billion in assets would be exempt.

The panel also agreed to let regulators set higher standards of duty for broker-dealers who give financial advice and agreed to give investors an easier way to nominate corporate board directors.

They also watered down a provision to give shareholders a nonbinding vote on executive pay. That vote would take place once every two or three years, not annually.

(Additional reporting by Roberta Rampton, Rachelle Younglai and Andy Sullivan; writing by Andy Sullivan; Editing by Alistair Bell, Jackie Frank and Anthony Boadle)