WASHINGTON — After a marathon final day of debate, the regulatory reform process ended in the early hours of Friday in the same dramatic manner it had been conducted for more than a year: with a near breakdown followed eventually by a miraculous save.

After several hours of late-night wrangling, conferees resolved the two most problematic questions: how to finalize a ban on proprietary trading and limit banks' investment in hedge funds and private equity firms, and whether to force banks to spin-off their derivatives trading desks.

The resolution of those and other pending issues meant the regulatory reform bill is now complete and will return to the full House and Senate for votes next week, where it is expected to pass.

Although there is certain to be more rhetoric and debate next week over the merits of the bill, the end of the conference committee means the final legislation can no longer be altered, short of unforeseen circumstances.

"Nobody thought we could get this done," said Senate Banking Committee Chairman Chris Dodd, speaking immediately after the conference concluded. "It took a crisis to bring us to the point where we could actually get this done."

Although at some points the bill looked like it could still fall apart, lawmakers reached final agreement roughly 20 hours after debate first began early Thursday.

Sen. Blanche Lincoln, the chairman of the Senate Agriculture Committee, refused to budge on a provision that would force banks to spin off their swaps desks, while moderate House Democrats threatened to vote against the bill if the derivatives measure was not removed.

The final version of the Volcker Rule also remained in limbo, with Senate Democrats and Republicans sparring over how much to allow banks to invest in private-equity firms and hedge funds.

Ultimately, the Lincoln amendment was essentially split into two, so that banks would have to conduct some derivatives activities in an affiliate while it could conduct others in the bank itself.

The derivatives provision was the last to be dealt with and for a time looked like it would not be resolved. Banks have vigorously opposed the Lincoln amendment, arguing it would cost them billions of dollars to spin off their derivatives units. Regulators, too, had argued against the provision, saying it would drive derivatives trades overseas or underground, where they would not be regulated.

For weeks, banking lobbyists and moderate Democrats had been assured the provision would be watered down or eliminated as the final legislation was settled. But Lincoln had continued to hold the line as her political power was bolstered by her primary victory on June 8. The issue finally came to a head Thursday after the New Democrats, a coalition of moderate members, threatened to oppose the final bill if the provision was not removed.

That resulted in a wave of negotiations between Lincoln and House Democrats over the final provision. Around midnight, House Agriculture Committee Chairman Collin Peterson, D-Minn., suggested the basic solution where some swaps should be forced into an affiliate while others would be allowed within the bank. The Treasury Department was instrumental in helping to craft the new language.

"What can be retained by banks will be interest rate swaps, foreign exchanges, credit derivatives relative to investment grade entities that are cleared, gold and silver and hedging for the bank's own risk," Peterson said. "What would be required to go under the affiliate would be cleared and non cleared commodities, energies and metals… and all equities and any non cleared credit default swaps."

Peterson said the split was based on what activities banks could already engage in.

"Currently banks are not allowed to invest in commodities, energy; they are not allowed to invest in equities or trade in equities or agriculture," he said. "These are things that are currently not allowed in banking, so why we would allow them to do the derivatives that are related to those things that are currently not allowed in banks? So we took those provisions and put them in the affiliate. These are generally the most risky parts of these derivatives."

He was backed by House Financial Services Committee Chairman Barney Frank, who said the amendment was "the best compromise we can get."

The revised measure was welcomed by some in the banking industry, who noted that it would continue to allow them to engage in interest rate swaps, one of the most prevalent kinds of derivatives institutions engage in.

The provision would also specifically forbid the bailout of any swaps unit and be phased in over two years.

Republicans sought to remove the provision entirely. Sen. Saxby Chambliss, R-Ga., argued the Volcker Rule provision to ban proprietary trading would make the Lincoln measure moot, but the Arkansas Democrat rejected that argument.

"We need to get banks back to the business of banking," Lincoln said. "Clearly, swap dealing is a risky activity and it is something that we need to deal with… banks need to be making small business loans… and not playing in swaps."

Sen. Judd Gregg, R-N.H. said the Lincoln provision was just political and would cause a credit crunch.

"You will have less credit in the system," he said. "It's not going to make [the system] safer. It's not going to make it sounder."

Ultimately, however, conferees agreed to accept the Peterson amendment largely unchanged.

Rep. Gregory Meeks, D-N.Y., the House Financial Services Committee's international monetary policy subcommittee chairman, worked with New Democrats and New York Democrats on an alternative to the Lincoln swaps ban that would have let regulators push out swaps trading only if they had taken other steps to protect the system, including implementing the Volcker Rule and raising capital.

But Sen. Charles Schumer, D-N.Y., told Meeks that he would not have the votes in the Senate.

In an interview, Meeks said that he was disappointed with the outcome because he has concerns there could be unintended consequences of the partial pushout of derivatives activities.

"I'm scared that businesses could be driven t

o move abroad," he said. "I'm nervous about that because there are various pieces that are pushed out that I wish were still in as far as derivatives go, which I hope does not force some derivatives into the shadow market."

The derivatives piece was finalized roughly three hours after the conference finalized the Volcker Rule, which would limit bank investment in private equity firms and hedge funds. Under the final measure, banks would be allowed some limited investment in such companies equal to as much as 3% of the total ownership interests of the fund. However, their collective investments in those firms could not exceed 3% of the bank's Tier 1 capital.

Senate conferees had earlier suggested a total limit of 3% of tangible common equity -- a more restrictive standard -- but were rebuffed by House conferees.

Citing the inclusion of an amendment from Sen. Susan Collins, R-Maine, in the final bill that would ban the use of trust-preferred securities from counting as Tier 1 capital, Senate Banking Committee Chairman Chris Dodd agreed the House standard made sense.

The final language also restored the so-called Hotel California provision, which would block bank holding companies from converting to investment bank status to escape provisions of the Volcker Rule.

It would allow an initial 2 year transition period for investments in liquid funds, with the possibility to win a maximum of three 1-year extensions for a total of five years. For illiquid investments, there would be a 2 year transition with the possibility of a single extension of no more than five years, for a maximum transition of seven years.

The provision would also provide exemptions for purchasing and selling government obligations, underwriting or market-making related activities, risk-mitigating hedging activities, insurance activities, and Small Business Administration small business investment company investments.

The measure would prohibit any transaction that creates a conflict of interest and limit employee investments in funds.

The conference committee also added a tax on banks to pay for the bill. Under the agreement, banks with more than $50 billion of assets and hedge funds with more than $10 billion would be subjected to risk-based special assessments levied by the Federal Deposit Insurance Corp. The agency would be required to collect $19 billion from September 2012 through September 2015, which would be put into a fund at the Treasury Department.

Conferees also resolved other outstanding issues late Thursday, including preemption and underwriting standards.

The two sides adopted preemption language that would only let the Office of the Comptroller of the Currency preempt state laws if they "prevent or significantly" interfere with the business of banking. Preemption experts mostly agreed that such language would make it harder for the OCC to preempt a state law and strengthen state regulators' case in court.

Conferees also agreed on new underwriting standards. Under the deal, regulators would define a class of mortgages that would meet a requirement of the legislation that says lenders must ensure borrowers can repay their loans. Such qualified mortgages would be protected from legal liability, such as the borrower's right to rescind the loan and seek damages.

Regulators must consider several issues when defining such loans, including appropriate debt-to-income ratios and fully documented income verification.

Certain loan features such as negative amortization, prepayment penalties and balloon payments would bar loans from meeting the qualified safe harbor. Qualified mortgages would still have to be a net tangible benefit to borrowers.

A narrowed version of the Senate risk retention proposal was also included in the bill where lenders packaging qualified mortgages into securities would be exempted from a 5% risk retention provision.

In one final note, the conference ended with conferees deciding to rename the legislation the Dodd-Frank Act in honor of the two banking chairmen who have championed the legislation for more than a year.