Mondelez International (MDLZ) agreed to merge its coffee business with D.E. Master Blenders, forming a new company that can better compete with Nestle and allowing Mondelez to focus on its snack portfolio.

Also on Wednesday, Mondelez detailed a restructuring plan and reported first-quarter earnings that beat Wall Street expectations. Shares rallied 7.7% to $37.93 on the news.

Mondelez and D.E. Master Blenders, which owns the Douwe Egberts and Pilao brands, are the second- and third-largest coffee companies by sales, respectively. Including global leader Nestle, the three firms account for about 40% of the world’s coffee market.

The new coffee company is expected to have annual revenue of at least $7 billion. It will be based in the Netherlands and named Jacobs Douwe Egberts.

Under the agreement, Mondelez will receive roughly $5 billion in cash and a 49% stake in the combined company.

D.E. Master Blenders split from Sara Lee, now called Hillshire Brands (HSH), about two years ago. It was then acquired by investment group Joh. A. Benckiser for $9.8 billion last year. JAB also owns U.S.-based Peet’s Coffee and Caribou Coffee.

Mondelez, which is known for iconic snacks like Oreo cookies and Ritz crackers, was spun off by Kraft in 2012. Mondelez’s coffee brands include Jacobs and Gevalia.

Mondelez said merging its coffee business with D.E. Master Blenders will allow the company to reduce its supply chain and slash overhead costs. Activist investor Nelson Peltz, who received a seat on the Mondelez board earlier this year, has pushed the company to rein in expenses.

Mondelez anticipates the restructuring will provide savings of at least $1.5 billion by 2018.

In the first quarter, Mondelez logged a 1.2% decline in input costs and a 2.9% drop in selling, general and administrative costs.

The Deerfield, Ill.-based company said its profit fell 70% in the latest period to $163 million, or nine cents a share. A year earlier, Mondelez reported a profit of $536 million, or 30 cents a share. Adjusted earnings climbed four cents to 39 cents a share.

Revenue was down 1.2% at $8.64 billion, matching expectations. Analysts were looking for an adjusted profit of 35 cents a share

Mondelez also lowered its full-year outlook for organic net revenue growth to 3% from 4%, citing weakness in emerging markets and lower coffee prices.

Follow Matthew Rocco on Twitter @MatthewRocco