General Mills is buying its way into the natural and organic food market as it wrestles with stagnating demand for its traditional packaged items.

The company said Monday that it has agreed to purchase Annie’s Inc., the firm known for its natural macaroni and cheese, for $820 million. The deal is the largest to date in a series of natural and organic acquisitions for General Mills.

The company that sells Lucky Charms, Toaster Strudel and Totino’s pizza rolls will pay $46 per share, a 37 percent premium on Annie’s closing price of $33.51 on Monday. The price reflects how important it is for the Golden Valley-based packaged food giant to gain a better foothold in the natural and organic market.

“Annie’s is one of the leaders in the natural and organic space. That’s where consumers are moving, and Mills wants to be better represented there,” said Jack Russo, an analyst with Edward Jones in St. Louis. “For these little growth companies that can boost your presence in an area that you want to have a bigger presence in, you’ve got to pay for it.”

Annie’s annual sales of $204 million would bring General Mills’ natural and organic sales to about 3 percent of total revenue. The company’s previous natural and organic acquisitions include Cascadian Farm, Larabar and Food Should Taste Good. Together those brands account for $330 million of the company’s $17.9 billion in annual sales.

Erin Lash, an analyst with Morningstar in Chicago , said that with Annie’s representing a relatively small piece of General Mills’ overall business, the purchase price “strikes us as quite rich at first blush,” said. She said the deal highlights the “muted growth prospects within the packaged good landscape.”

Given the growth prospects for natural and organic food, however, Lash views the purchase as a positive for General Mills.

“We also think the added distribution channels through which Annie’s products are sold could open new doors for General Mills,” she wrote in a note to investors. “Management has proved to be prudent acquirers in the past, and we don’t expect this deal to be any different.”

Headquartered in Berkeley, Calif., Annie’s Inc. is named after Annie Withey, who created an upmarket popcorn in her Boston kitchen in the 1980s called Smartfood. The popcorn was later acquired by Frito-Lay, and Withey and then-husband Andrew Martin went on to start Annie’s Homegrown in 1989.

They marketed her macaroni and cheese as natural, with no preservatives or dyes. In the early days she answered letters from customers and handed out cups of white cheedar macaroni at ski lodges in New England.

The company was acquired by investors in 1999 and now markets more than 145 products in more than 35,000 retail locations in the United States and Canada. Withey, who still lives in Connectictut, retains the title “inspirational president.”

General Mills chief operating officer Jeff Harmening said the acquisition makes sense for General Mills in part because of Annie’s strength in convenient meals and snacks -- both priorities for the food giant.

“Consumers know and trust Annie’s purpose-driven culture and authentic brand,” Harmening said in a statement. “We believe that combining the Annie’s product portfolio and go-to-market capabilities with General Mills’ supply chain, sales and marketing resources will accelerate the growth of our organic and natural foods business.”

The transaction is expected to close before the end of the year, and General Mills said it will pay for it by borrowing money.

General Mills employs just over 5,300 people in Minnesota, primarily at its headquarters, but also at two research facilities, along with a flour mill in Fridley and a food service plant in Chanhassen.

U.S. retail sales in the company’s fourth quarter were down 1 percent compared with a year earlier, and soft sales have bedeviled the entire packaged-food industry for several quarters now.

There’s speculation that shoppers are migrating away from some of the traditional offerings of packaged-food makers, and toward what they perceive as healthier options.

Asked in a conference call this summer how General Mills would break the disappointing sales trend, CEO Ken Powell said there is no “silver bullet,” but he nodded toward changes in consumer preferences.

“Consumers’ definitions of health and well-being are changing, and we need to be very attuned to that,” Powell said. “We are in changing times. We are a marketing company, and our job is to understand the change and capitalize on it.”