Procter & Gamble Co. gave a somber outlook for the year ahead, predicting slower sales and historically high costs for raw materials and transportation as inflation picks up and the global health crisis continues.

The maker of Pampers diapers and Tide detergent posted sales gains in almost every business unit in the most recent quarter, though growth slowed and profit margins tightened as the company spent more to make and deliver its products.

The results come a day after P&G announced that David Taylor would step down in November as chief executive after a six-year run. He will be replaced by top deputy Jon Moeller, who has been P&G’s chief operating officer for the past two years and was previously its finance chief.

“Commodities and cost pressure have escalated significantly,” Mr. Taylor said in an interview. “You have a tough external environment and a pandemic that’s raging; many parts of the world are at the worst they’ve ever been.”

P&G expects to take a $1.9 billion after-tax hit on higher freight and commodity costs and predicts sales growth to slow by half for the fiscal year that began July 1. Rival Unilever PLC said last week it was grappling with higher costs for ingredients, packaging and transportation, which would likely lower its full-year profitability.

“Commodities and cost pressure have escalated significantly.”

— David Taylor, CEO of Procter & Gamble

P&G said earlier this year that it planned price increases starting in September to help offset rising costs. Other makers of household staples and consumer goods have also unveiled plans to raise prices on everything from bottled water to paper towels.

SHARE YOUR THOUGHTS

How has your buying of consumer products changed compared to a year ago? Join the conversation below.

P&G is also taking steps to cut back on shipping costs, finance chief Andre Schulten said in an interview. To offset freight and transportation expenses, P&G is allowing some online retailers to use its warehouses as distribution centers, he said. In some cases, the company is shipping goods directly to retailers, bypassing P&G facilities that sort and reload cargo in service of delivering the optimal mix of products to retailers, particularly with bulky products such as paper towels and toilet paper.

P&G said organic sales, a measure that strips out deals and currency moves, increased 4% in the quarter ended June 30, and 6% for the fiscal year that also ended in June. That follows a 6% sales gain in the prior fiscal year, which was P&G’s biggest gain in more than a decade.

During the latest quarter, P&G’s net sales rose 7% to $18.94 billion, above the consensus forecast of $18.37 billion from analysts polled by FactSet. Core earnings per share fell 3% from a year ago to $1.13.

For fiscal 2022, the company predicts net and organic sales growth of 2% to 4%, compared with the previous fiscal year’s 6% organic growth. It predicts core earnings-per-share growth of 3% to 6% relative to the previous fiscal year’s $5.66.

P&G notched substantial sales gains amid the pandemic but has experienced less dramatic sales swings compared with rivals. Kimberly-Clark Corp. and Clorox Co. , with product lineups more focused in cleaning and home care, had big gains last year and losses more recently as shoppers stopped stockpiling toilet paper and cleaning products.

Kimberly-Clark, maker of Cottonelle toilet paper and Scott paper towels, last week reported its second-straight quarterly sales decline. Clorox reported a 1% sales drop in the year’s first quarter, following three straight periods of gains above 20%. The company is expected to post another decline when it reports quarterly sales next week.

In its latest quarter, P&G logged slower growth in its home-care unit, which includes Dawn soap, Swiffer floor cleaners and Microban disinfectants. That sluggishness was offset by higher sales of products less tied to the pandemic, such as Crest toothpaste, Gillette razors and SK-II, a line of high-end skin-care products driving outsize growth.

The U.S. inflation rate reached a 13-year high recently, triggering a debate about whether the country is entering an inflationary period similar to the 1970s. WSJ’s Jon Hilsenrath looks at what consumers can expect next. The Wall Street Journal Interactive Edition

Write to Sharon Terlep at sharon.terlep@wsj.com