Heinz is buying Kraft Foods to create the world's fifth largest food and beverage company, with sales of about $28 billion.

Kraft shares surged more than 33% Wednesday.

Kraft owns popular brands such as Jell-O, Maxwell House coffee and Planters peanuts. Heinz, of course, is famous for its ketchup, and also owns Lea & Perrins and Ore-Ida.

Kraft shareholders will receive stock in the Kraft Heinz Company, plus a special dividend of $16.50 per share funded by a $10 billion cash injection by Heinz owners 3G Capital and Warren Buffett's Berkshire Hathaway (BRKA).

This isn't the first time that Buffett has worked with 3G Capital. In 2013, they teamed up to acquire Heinz.

Berkshire Hathaway also helped 3G Capital finance Burger King's purchase of Canadian chain Tim Hortons last year.

Once the deal is done, Heinz shareholders will own 51% of the combined firm while Kraft shareholders will get a 49% stake.

"By bringing together these two iconic companies through this transaction, we are creating a strong platform for both U.S. and international growth," said Heinz chairman and 3G managing partner Alex Behring.

Another big reason for the deal: Cost cutting at Kraft. 3G is known for slashing costs at bloated companies, and Kraft needed help if it was going to start boosting profits.

Just last week, Kraft recalled 240,000 cases of macaroni and cheese, because some boxes may have been contaminated with pieces of metal.

Kraft Heinz will have headquarters in both Pittsburgh and the Chicago area. Heinz CEO Bernardo Hees will be CEO of the combined group.

Berkshire Hathaway will have three seats on the new board.

Heinz and Kraft are aiming to generate $1.5 billion in annual cost savings by the end of 2017.

The merger has been agreed by the boards of both companies, but needs regulatory approval and the support of Kraft shareholders. The companies expect the deal to close in the second half of 2015.