DEUTSCHE BANK AG has finalized a deal with BNP Paribas SA to transfer its prime brokerage business to the French bank as part of the German lender’s biggest overhaul in recent history.

About 1,000 Deutsche Bank employees will transfer to the French bank through 2021, according to people with knowledge of the matter. The two lenders expect that client balances — which halved to about $80 billion at the German bank — will recover now there’s more certainty on the future of the business, the people said, asking not to be identified as the matter is private.

The two firms had agreed on a deal in principle in early July as Deutsche Bank Chief Executive Officer Christian Sewing retreats from equities trading, which includes the prime business serving hedge funds. But finalizing the accord has been complicated by a flood of client defections. For Sewing’s counterpart at BNP, Jean-Laurent Bonnafe, a deal could bring the scale needed to compete with the bigger players.

The agreement could vault BNP Paribas into the global top 4 of prime brokerages over the next 12 months, one that may eventually have between $250 billion and $300 billion in client balances, according to the people. Deutsche Bank will continue to manage the platform until clients can be passed over to the French lender, the two banks said on Monday.

“Now that the deal has signed we believe we have the basis to regain and expand on the business,” Deutsche Bank Chief Operating Officer Frank Kuhnke said in a telephone interview. The deal “provides tangible real benefits for our customers and gives our staff a way forward.”

The deal comes just a few days after Deutsche Bank sold the first portfolio of equity derivatives, which is another key plank of its plan to close equities trading and get the associated assets off its balance sheet quickly and without incurring restructuring costs or write-downs. The bank has said it will provide details about its progress during its third-quarter results presentation on Oct. 30.

Ashley Wilson is one of the co-heads overseeing the German lender’s unwanted assets as part of Deutsche Bank’s retreat. When the two European banking giants first discussed the deal, Deutsche Bank’s prime brokerage business was set to move about €150 billion ($165 billion) of balances, people familiar with the matter have said previously. Yet clients put off by the uncertainty pulled about $1 billion of funds per day at one point, the people said at the time.

Prime-brokerage divisions cater specifically to hedge funds, lending them cash and securities and executing their trades, and the relationships can be vital for investment banks. The prime business generated about $18.3 billion in fees in 2018 industrywide, about the same as revenue from trading corporate debt and currencies combined, data from Coalition Development Ltd. show.

Deutsche Bank, which became a force on Wall Street in the wake of the financial crisis, has struggled to keep hedge-fund clients in recent years as it lurched from one problem to another. US rivals JPMorgan Chase & Co., Morgan Stanley and Goldman Sachs Group Inc. are the top three firms in the business, while Deutsche Bank wasn’t among the top seven prime brokers in 2018, Coalition data show.

BNP, based in Paris, has sought to profit from crisis before. The lender bought Bank of America Corp.’s prime-brokerage business in June 2008 as the credit crunch raged, acquiring more than 500 clients and 300 employees. Still, the firm has one of the smallest prime units among global banks, according to Coalition.

Deutsche Bank’s hedge fund balances have been declining throughout the year as speculation swirled around Sewing’s intentions for the prime brokerage unit.

One major client — Renaissance Technologies — has been pulling money from the firm, people familiar said earlier. — Bloomberg