PepsiCo Inc.’s PEP 0.44% longtime leader, Indra Nooyi, will step aside as chief executive this year, handing the future of the soda-and-snacks company to one of her lieutenants at a time when shifting consumer tastes are roiling its markets.

Ms. Nooyi, 62 years old, steered the maker of Mountain Dew, Gatorade and Doritos chips for a dozen years through the changing landscape, defeating an activist investor’s attempt to break up the company. She pushed PepsiCo far beyond its cola roots, expanding with mixed results into hummus, kombucha and other healthier products.

PepsiCo’s annual revenue increased 81% during her tenure to $63.5 billion last year, but recently executives have pledged to ramp up advertising as its core soda brands lost market share.

She will leave the CEO role on Oct 3 and the position of chairman early in 2019. Ramon Laguarta, a 22-year PepsiCo veteran who was promoted to president last year, will take over as CEO, the company said Monday. When Mr. Laguarta was elevated to the No. 2 role last September, Ms. Nooyi said she intended to remain CEO “for the foreseeable future.”

Ms. Nooyi’s exit is the latest in a series of high-profile CEO departures in the food-and-beverage industry, as big brands lose shelf space to smaller, trendier entrants and established players scramble for growth. Rival Coca-Cola Co. and Oreo maker Mondelez International Inc. switched leaders last year while Campbell Soup Co. changed its CEO earlier this year. Still, Ms. Nooyi’s tenure was twice as long as the average for S&P 500 CEOs, which was five years as of the end of 2017, according to Equilar.

Ms. Nooyi joins several other prominent women CEOs, including Campbell Soup’s Denise Morrison, Hewlett Packard’s Meg Whitman and Mondelez’s Irene Rosenfeld, who have left their roles recently. Just 25 women currently run an S&P 500 company, according to research group Catalyst, a level that hasn’t changed much in the past decade even though women are half of the U.S. workforce.

Related Video Sales for the largest packaged food companies have been down the past few years as changing tastes, startup brands and e-commerce giants threaten from all angles. WSJ’s Ken Brown takes us on a walk through the supermarket. Photo: Getty Images.

In an interview, Ms. Nooyi said she had asked PepsiCo’s board a year ago to plan for her departure. “Twelve years is a long time, and I’d like to do something different with my life,” she said she told the board. “This wasn’t a discussion out of emotion or anything of that sort.” She said she will decide early next year what to do next.

Ms. Nooyi said she had succeeded in diversifying the company’s portfolio away from a reliance on sugary sodas and salty snacks. Her biggest disappointment, she said, was not being able to move more quickly, which she attributed to the 2008 recession and the distraction of activist investors. “I would have loved to have done things faster,” she said.

At the start of trading Monday, PepsiCo’s total shareholder return was 149% since Ms. Nooyi took over as CEO on Oct. 1, 2006, according to FactSet, compared with 197% at Coca-Cola and 173% for the S&P 500 index. Total return includes share price appreciation plus dividends.

PepsiCo’s market capitalization was $165 billion based on Friday’s closing price, compared with $200 billion for Coca-Cola. When Ms. Nooyi took over, PepsiCo’s market cap of $106 billion was slightly larger than Coca-Cola’s, at $104 billion.

Ms. Nooyi’s departure opens up the possibility of a company restructuring, some analysts said Monday. Shares of PepsiCo rose nearly 1% to $117.38 on Monday.

“We wonder—with new leadership at the helm—will [Pepsi] begin to consider more strategic options? We think the answer could be yes,” Wells Fargo analyst Bonnie Herzog wrote in a note Monday. Potential moves include selling off bottling operations, as Coca-Cola recently did, or spinning off the beverage business, she said.

“Consumer staples is hard. They’re in a space where margins are squeezed and squeezed,” said Jenny Van Leeuwen Harrington, CEO and portfolio manager at Gilman Hill Asset Management. “She has done a good job of moving away—to the degree that it’s possible—from soda and salty snacks.”

Board members praised Ms. Nooyi’s tenure, which led the company to embrace healthier products before rival Coca-Cola, and they highlighted Mr. Laguarta’s experience in international markets.

New PepsiCo boss Ramon Laguarta has been at the company since 1996, climbing the ranks. Photo: Andrey Rudakov/Bloomberg News

“The board is confident that he is the right person to usher in this next chapter of growth,” said PepsiCo director Ian Cook, who is CEO of Colgate-Palmolive Co.

Mr. Laguarta, 54, a native of Barcelona, rose through the ranks and previously ran PepsiCo’s Europe business. “We’ll continue to be a company that reacts in a proactive way on the forefront of all these trends, be it consumers moving to healthier spaces or… e-commerce and this new way of shopping, or geopolitics,” Mr. Laguarta said in an interview.

Ms. Nooyi said investors should give Mr. Laguarta time to set his own course. “He should do whatever he thinks is right for the company,” Ms. Nooyi said. “Whatever he chooses to do, I will support him.”

Ms. Nooyi grew up in Chennai, India, where during food shortages in the 1960s her middle-class family stood in line for rice rations studded with stones. When Indra and her sister were young, their mother challenged them at the dinner table each night to give speeches about what they would do if they were prime minister or another world leader. After the speeches, their mother would vote.

Ms. Nooyi came to the U.S. in 1978 on a scholarship to the Yale School of Management, and worked at several companies before joining PepsiCo in 1994 as head of strategy. She was chief financial officer and president before she was named chief executive, succeeding Steve Reinemund.

After becoming CEO in 2006, Ms. Nooyi said she wanted to make PepsiCo “a defining corporation of the 21st century.” “Nobody’s going to remember you for delivering earnings to stockholders; they will remember you for the lasting impact you made on society,’’ she said in a 2009 speech.

She led a push into healthier, more nutritious products, arguing that a more diverse product portfolio would be good for business, too. Obesity had become a global crisis. Consumers were reading food labels more carefully. U.S. per capita consumption of soda, long a growth engine, had begun to decline.

She bought a 50% stake in U.S. hummus maker Sabra in 2008 and formed a joint venture with Saudi Arabian dairy giant Almarai in 2009, the same year PepsiCo bought Brazilian coconut-water company Amacoco. In 2010, she oversaw the $5.4 billion acquisition of Russian dairy and fruit-juice maker Wimm-Bill-Dann.

Ms. Nooyi ramped up R&D spending and dispatched executives to Iceland to research seaweed, India to study Ayurvedic medicine and Africa and the Amazon jungle to learn about ancient grains, berries and plants.

In 2010, she set a goal of tripling PepsiCo’s revenue from nutritious products to $30 billion by the end of the decade. That ambition has since been taken down a notch: The current goal—which Mr. Laguarta says he is targeting—is for sales growth of nutritious products to outpace the rest of the portfolio by 2025.

PepsiCo cut its profit forecasts twice in 2011. Investors accused Ms. Nooyi of neglecting core brands. The problems attracted Nelson Peltz, the activist investor behind Trian Fund Management LP, who dismissed the nutrition push as a distraction and accumulated stock in a campaign to split up PepsiCo.

In February 2012, when PepsiCo issued another profit warning, Ms. Nooyi announced a $1.5 billion cost-cutting program and promised to boost marketing for its big beverage brands. Investor pressure reared up again in 2013 when Mr. Peltz campaigned unsuccessfully for PepsiCo to shed its beverage business. Trian exited its stake in PepsiCo in 2016.

In recent years both Coca-Cola and PepsiCo have used higher prices and smaller packaging to help boost revenue as soda consumption falls.

However, PepsiCo’s North American beverages unit has been struggling again. The company last year shifted too much marketing money and shelf space to new, healthier products, hurting sales of Pepsi-Cola, Mountain Dew and Gatorade.

The weak sales once again put pressure on Ms. Nooyi to consider spinning off the company’s bottling operations or even split off its beverage business. Ms. Nooyi said earlier this year the company was examining options for the bottling operations.

In the interview, Mr. Laguarta declined to discuss his plans for the bottling operations. “We’ve seen sequential acceleration of the business,” he said. “We’ll continue the journey.”

PepsiCo this year has increased advertising spending on its core soda brands. The beverage unit’s decline slowed in the second quarter.

PepsiCo said the rest of its management team, including finance chief Hugh Johnston and R&D chief Mehmood Khan, are expected to remain in their current roles.

Write to Jennifer Maloney at jennifer.maloney@wsj.com