Starbucks Corp. is buying the rest of its East China joint venture in a $1.3 billion transaction, marking the biggest deal ever for a company that sees China as a huge growth opportunity.

The Seattle-based coffee chain will acquire the remaining 50 percent of the business from partners President Chain Store Corp. and Uni-President Enterprises Corp. Starbucks also is divesting its 50 percent stake in a separate joint venture in Taiwan, according to a statement Thursday.

The move underscores Starbucks’ bet that China will be one of the company’s top sales drivers in coming years. It’s wagering that the nation’s growing middle class and urbanization will give it a huge population of potential coffee drinkers to tap.

The deal mirrors the company’s strategy in Japan, where Starbucks entered the country with a joint venture, spent time learning the local market and then brought the business back in house, said Jennifer Bartashus, an analyst at Bloomberg Intelligence. In 2014, Starbucks agreed to buy out its Japanese joint venture with Sazaby League and other partners for about $913.5 million.

“With the level of expectations they have for China, it isn’t really a surprise that they want to exert as much control over the stores as possible,” Bartashus said.

Starbucks shares gained as much as 1.9 percent at $59.03 in New York on Thursday. The stock had climbed 4.4 percent this year through the close of trading on Wednesday.

Starbucks plans to operate 5,000 cafes in mainland China by 2021, a goal it reaffirmed on Thursday. The company currently has 2,800 locations there.

The deal gives Starbucks 100 percent ownership of about 1,300 cafes in Shanghai and in the Jiangsu and Zhejiang provinces. In the Taiwanese transaction, its partners will acquire Starbucks operations in the territory for about $175 million. The Starbucks business there, which was founded in 1997, has about 410 cafes.

“Unifying the Starbucks business under a full company-operated structure in China reinforces our commitment to the market and is a firm demonstration of our confidence in the current local leadership team,” Chief Executive Officer Kevin Johnson said in the statement.

The status of Taiwan is a sensitive political issue in China. The Chinese government considers Taiwan a renegade province. The decision to sell the business there was about allowing its partners to “maximize the opportunities” for the brand in Taiwan, according to a spokeswoman for Starbucks.

Dunkin’ Donuts Inc., a major Starbucks rival in the U.S., has a much smaller presence in China. The chain failed in two previous attempts to crack the Chinese market, but is now working with two franchisees there and has 34 stores, including 16 in Beijing. Dunkin plans to grow to 1,400 location in the world’s most populous country over the next 20 years.

Chinese consumers still drink a relatively small amount of coffee, but the category is growing fast and could eventually surpass tea, according to Dunkin’ CEO Nigel Travis.

China is the fastest-growing market outside the U.S. for Starbucks. With full control of the local operations, Starbucks can enhance the coffee and in-store experience, said its China CEO, Belinda Wong. It also plans to rely more on technology in the country. Starbucks’ mobile-ordering app has been key to locking in customers in the U.S.

The deal is another sign that Starbucks views China as key to its future and can’t let execution slip there, said Jack Russo, an analyst at Edward Jones.

“Asia is incredibly important for them — there’s no mistaking that,” he said.