Jefferies Group (JEF) said early Monday that it has agreed to merge with one of its largest shareholders in an all-stock deal, sending shares of the investment banks rallying as much as 20%.

Leucadia National (LUK), which owned a 29% stake in Jefferies ahead of the news, will offer 0.81 of a share of Leucadia's common stock for each Jefferies share.

News of the all-stock deal sent Jefferies' stock soaring Monday. Although shares were off earlier highs, the stock was still up about 11% mid-morning. Leucadia's stock, which initially gained about 2%, turned lower mid-morning.

Ahead of the Leucadia deal, Jefferies' stock was nearly flat for the year. The bank failed to partake in the broader stock market rally that's been particularly beneficial to bank stocks. Leucadia's stock has also struggled this year, losing more than 4% since January.

Leucadia operates a diverse group of businesses, from real estate to beef processing, lumber manufacturing and mortgage servicing.

Jefferies, valued at $4.1 billion in book value, is nearly double the size of the rest of Leucadia's holdings. In a presentation, Leucadia said that Jefferies' investment banking relationships will help the holding company find more investment opportunities.

Jefferies CEO Richard Handler will become CEO of the merged entity, while Leucadia Chief Executive Ian Cumming will retire once the deal closes.

Recently, Jefferies was part of an investing team that rescued Knight Capital (KCG) after a massive trading glitch nearly crippled that trading firm.

Last year, as the sovereign debt crisis in Europe heated up and MF Global collapsed, Jefferies was forced to fight off concerns over its European exposure and whether that could put the bank into a Lehman-like scenario. In November 2011, as the bank's shares tumbled, Jefferies rapidly shrunk assets on its balance sheet and sold much of its stake in European sovereign debt. Those moves put the bank on solid footing.

Leucadia's buyout of Jefferies is the latest in what's expected to be a string of acquisitions of small to midsize banks by larger companies, as smaller financial institutions struggle under the weight of expensive regulations.