By Annie Gasparro

General Mills Inc. said the coronavirus-fueled surge in grocery sales is waning, increasing pressure on food makers to hold on to the new shoppers who tried their brands during the height of the pandemic.

The packaged-food industry has caught a tailwind for much of this year because the pandemic has changed how consumers approached food. Families have bought more groceries to eat at home amid closures of restaurants and capacity limitations on dining rooms.

General Mills said Wednesday that it has gained market share in cereal, pet food and other categories in the latest quarter. Its sales rose 10% on a comparable basis, which excludes currency fluctuations and the effect of deals.

That growth was slower than in the spring, when consumers broadly quarantined at home. General Mills said the reopening of restaurants and easing of pandemic-related restrictions in recent months has contributed to the moderating in its sales growth. Campbell Soup Co. said earlier this month that the pace of its sales growth had also moderated in its latest quarter.

General Mills, maker of Cheerios, Yoplait and Betty Crocker, said it is making investments designed to hang on to the ground it has gained in the past six months, such as increased marketing spending and added supply-chain capacity. Chief Executive Jeff Harmening said he doesn't want to look back after the pandemic and see that General Mills didn't do enough to capitalize on the unprecedented shift to eating at home.

"We're doing everything we can now to sustain the growth momentum that we have," he said on a conference call.

Shares of General Mills rose 0.4% to $58.21 in morning trading.

Other food giants have struggled to maintain market share amid the pandemic, often because they couldn't make enough of their most popular items to meet demand.

Some investors have questioned the need for companies such as General Mills and Campbell Soup to spend more on marketing while demand for their products is so high. But even with the added costs, General Mills' profit margin improved in the latest quarter.

Profit in the quarter ended Aug. 30 rose to $638.9 million, or $1.03 a share, from $520.6 million, or 85 cents a share, in the same period a year earlier. The company's adjusted profit of $1 a share surpassed the 87 cents a share that analysts expected.

Revenue rose to $4.36 billion from $4 billion a year ago. General Mills' North America grocery business logged 14% sales growth. The Minneapolis-based company said sales grew for products such as Pillsbury refrigerated baked goods, Betty Crocker dessert mixes and Progresso soup. Its U.S. cereal sales were up 10%. Snack sales fell 2%.

--Micah Maidenberg contributed to this article.

Write to Annie Gasparro at annie.gasparro@wsj.com