Amazon said Friday it has agreed to buy Whole Foods Market for $13.7 billion, a stunning move to boost its growing grocery business.

The Seattle-based online retail giant will pay $42 per share in an all-cash deal. That's 27% higher than Whole Foods' Thursday closing stock price of $33.06.

The deal requires approval by Whole Foods' shareholders and regulators. The companies expect the deal to be completed in the second half of 2017.

Amazon has dabbled in brick-and-mortar operations, experimenting with a bookstore that opened in New York last month and plans to open "no-checkout" convenience stores. But the Whole Foods acquisition represents a dramatic departure from its early business model founded on online retailing and related technology.

Grocery retail is a notoriously thin-profit-margin business. And Whole Foods -- often derided as "Whole Paycheck" -- has struggled in recent years to keep up with emerging competitors that are expanding nationwide with cheaper items. Traditional grocery stores, such as Kroger and Safeway, have also widened their organic food selections in hopes of retaining customers who are increasingly looking to eat healthily.

The Austin-based company also has had to fend off encroachment into its specialty sector by other big-box stores, like Walmart, that have been increasing their food sections and adding more healthy merchandise. Discounters, like Aldi, and other online grocers have made their way in, too. The supermarket sector got even more crowded on Thursday, when German-based discount chain Lidl opened its first 10 U.S. stores.

“Millions of people love Whole Foods Market because they offer the best natural and organic foods, and they make it fun to eat healthy,” said Jeff Bezos, Amazon founder and CEO. “Whole Foods Market has been satisfying, delighting and nourishing customers for nearly four decades – they’re doing an amazing job and we want that to continue.”

John Mackey, Whole Foods Market co-founder and CEO, said the he agreed to the deal because it is "an opportunity to maximize value" for the company's shareholders. He will remain the company's CEO.

Whole Foods Market will keep its brand name and the headquarters will remain in Austin.

Whole Foods had been feeling the pinch not just from activist investors like Jana partners, but also declining quarter-over-quarter same-store sales. The chain had recently announced plans to close stores.

“They’re under lot of pressure to create shareholder value and turn back to a growth story, so they see this as an opportunity to leverage Amazon’s incredible retail online strength to perhaps gain the growth that’s coming from all the consumers moving to online platforms,” said Greg Wank, head of the Food and Beverage Industry Group at New York-based accounting and consulting firm Anchin Block and Anchin.

From Amazon’s perspective, it’s a way a quick way to grab a larger share of the grocery sector, which they’d begun with AmazonFresh and pilot stores.

“It’s a quick opportunity to become a real player and start doing their favorite thing, which is clicking on Walmart’s heels,” Wank added.

Shares of Amazon rose 1.5% to $978.88 in pre-market trading.

Follow USA TODAY reporter Roger Yu on Twitter @ByRogerYu.