The agreement gives Nestle, which owns the Nescafe and Nespresso brands, a strong platform for continued growth in North America, the company said in a statement.
is focusing on coffee as a main growth area and has already made some acquisitions in the sector.
The Starbucks business covered by the deal currently generates around $2 billion sales annually and includes coffee beans and ground coffee that Nestle will be selling in supermarkets around the world.
"This transaction is a significant step for our coffee business, Nestle's largest high-growth category," said Nestle CEO Mark Schneider in a statement.
"Both companies have true passion for outstanding coffee and are proud to be recognised as global leaders for their responsible and sustainable coffee sourcing," he said.
The deal does not include any of Starbucks' coffee shops and cafes.
Around 500 Starbucks staff will join Nestle, the company said, but the operations would continue to be located in Seattle.
Both companies would collaborate on "innovation and go-to-market strategies", it said.
Starbucks president and CEO Kevin Johnson hailed the deal as "historic" and said it would create a "global coffee alliance".
Nestle, which has been under intense shareholder pressure to improve its profitability, has begun to reposition itself since Schneider took over at the start of last year.
The former head of German healthcare group Fresenius has pushed for the food giant to focus in on a few areas, like bottled water, infant nutrition and pet care, with coffee a top priority.
While Nestle's Nespresso and other coffee products are omnipresent in Europe, they have had a harder time catching on in the United States.
Over the past 15 months, the company has clearly set its sights on high-end coffee brands in North America.
It snapped up a majority share in California-based Blue Bottle Coffee last September, and two months later
bought Texas company Chameleon Cold Brew.
At the same time, Nestle has been selling off parts of its confectionary business, handing over its US candy business earlier this year to Italy's Ferrero for nearly $3.0 billion.
Analysts hailed Monday's deal.
"Nestle has once again surprised the market with an unexpected transaction," Jean-Philippe Bertschy of Vontobel said in a research note.
He said that "coffee is one of the key growth pillars in the CEO's strategy, (and) allows Nestle to gain scale in the US, a weak spot so far."
He acknowledged that "the price might appear expensive, but given the returns, the deal could exceed the cost of capital within three to four years".
The transaction, which needs approval from regulators, should be finalised by the end of 2018, Nestle said, adding that the deal should start making a positive contribution to its earnings per share and its growth targets starting next year.
The company saw its shares swell 0.6 percent in mid-morning trading at 76.84 Swiss francs a piece, as the Swiss stock exchange's main SMI index was up just 0.15 percent.
Starbucks, meanwhile, said it will use the cash to accelerate share buybacks. The Seattle-based company said it now expected to return some $20 billion to shareholders through buybacks and dividends by 2020.