Indra Nooyi is smiling, but it’s not a happy smile. “How many women shop here vs. men?” she asks, standing in front of a bulky stack of 32-packs of Aquafina water in the aisle of Pete’s Fresh Market in Chicago. “More women,” one member of the six-person entourage of Pepsi executives and employees accompanying the CEO and chairman of PepsiCo PEP offers sheepishly.

It’s clear the question was rhetorical. Nooyi bends over, awkwardly lifts one of the 34-pound packages, and drops it with a dramatic thump. “Do they bring a guy to carry this out? Hello? Hello?” she says. “You need a forklift. Maybe because it’s inexpensive [$3.99], people are going to go through the hell, but we should watch out.”

Watch out is right. This is no ceremonial CEO tour; Nooyi is here to work. In a whirlwind, daylong visit to Chicago to see retail and restaurant customers including Pete’s Fresh Market, Jewel-Osco, Taco Bell YUM , and 7-Eleven, the head of this $66.7 billion (revenues) global company repeatedly spots tiny imperfections. She then announces them to the nervous executives, and whips out her iPhone to photograph the infraction, later dispatching the evidence to the person responsible.

To wit: an empty slot in a drink case; two halves of a Pepsi logo that didn’t align perfectly; stickers on a cooler door that impede the view of a logo inside; the fact that two brands of pretzels, Stacy’s and Rold Gold, are placed next to each other despite being marketed to very different customers. And on and on.

The infractions might seem insignificant—one missing can of Pepsi on one shelf in one store in one city in one country—but for Nooyi it is this level of detail that sets her company apart. “We ought to keep pushing the boundaries to get to flawless execution,” she declares. “Flawless is the ultimate goal.”

Indra Nooyi CEO of PepsiCo touring Pete's Fresh Market in Chicago. April 2015 Nooyi hoists a 34-pound package of water—one of PepsiCo’s brands—at Pete’s as executives and employees observe.Photograph by Mark Peterson for Fortune

As Nooyi, dressed in a fuchsia jacket, powers through the aisles, she’s also plucking competitors’ products to bring back to headquarters. She quickly hands them to PepsiCo’s communications chief, Jon Banner, who scrambles to keep pace. By the time we leave one supermarket she has purchased nearly a shopping cart’s worth of items that will be tasted, deconstructed, and evaluated by her team. As for those less-than-flawless moments? By the time the Pepsi jet lands back near the company’s suburban New York offices later that night, she says “90%” will already have been dealt with. Or else.

You can’t blame anyone at PepsiCo for feeling a sense of urgency—or embattlement—in recent years. Their staple products, soda pop and potato chips, are only slightly less demonized these days than cigarettes. Sales of carbonated soft drinks have dropped 14% over nine years, and Pepsi’s market share has fallen too. The company has struggled just to keep its revenues and profits essentially frozen in place for four years.

But little by little, green shoots have been emerging. Last year PepsiCo delivered 4% organic revenue growth (the company’s favorite non-GAAP metric, it removes the effects of acquisitions and currency fluctuations) for the second year in a row. PepsiCo insists this is the sign of a real comeback, and in 2015, the 50th anniversary of the marriage of Pepsi-Cola and Frito-Lay, there is reason for celebration. The company’s once-moribund stock has regained some fizz. (Translation: It’s been crushing the shares of rival Coke KO over the past three years, though not keeping up with the torrid S&P 500.)

For Indra Nooyi, now in her eighth year in the grueling crucible that is the leadership of one of America’s most globally recognized brands, it just may be a moment to exhale. You could even call it vindication. From the start of her tenure she dared to acknowledge what was obvious to everyone outside the business but unutterable to those inside it: Junk food makes people fat and harms their health. Nooyi began emphasizing products that are at least a bit healthier than the traditional chips and soda—a pivot some observers thought could sink the company. Now shoppers are proving her right.

Rank in Fortune 500: 44
Revenues: $66.7 billion
Profits: $6.5 billion
Employees: 271,000
Total Return to Shareholders
(2004-2014 annual rate):

Except it’s not that simple. Young consumers want healthier fare, but their definition of that turns out to be confounding and inconsistent. And plenty of people still flat-out love junk food. The company’s highest-growing unit this past quarter was its global snacks division. That makes Nooyi’s mission something like a riddle wrapped in a mystery inside an—well, you can understand the difficulty. It’s easy enough to extol the benefits of Propel Electrolyte Water, which has no calories, but a little trickier to bask in the glory of that nourishing elixir when your best-performing big soda brand is Mountain Dew, a drink so sugary and acidic that it has spawned its own dental condition, “Mountain Dew mouth.”

Nooyi, 59, isn’t ready to declare victory, but more and more her strategy is looking like the right one in a tough situation, especially compared with Coke, which has suffered for its reliance on soda. Nooyi, only the fifth person to run PepsiCo and a dark-horse choice—a woman, a foreigner, a onetime strategy consultant—has outlasted all but one of her predecessors and, at least for now, a powerful shareholder activist. She seems refreshed and energized. But her challenges remain daunting. Can she lift PepsiCo from a success that requires qualifiers and explanation (Better numbers than struggling Coke! Above-median performance in a weak category!) to the pure, sugary rush of surging profits?

Every CEO vows to manage for the long term, a promise honored most often in its breach. Sure enough, Nooyi has the requisite high-minded slogan: “Performance with purpose.” But unlike most corporate chieftains, Nooyi has actually pursued policies in line with those principles. In 2007, for example, Nooyi announced the company would cut water use by 20%, a target the company met three years early.

Nooyi’s biggest initiative posed considerable risk to the company: She publicly acknowledged that PepsiCo needed to change if it wanted to keep its most avid consumers alive. In one speech she said the next generation may be the first to “live for a shorter span than its predecessor.” In another she proclaimed that Pepsi must address “one of the world’s biggest public health challenges, a challenge fundamentally linked to our industry: obesity.” This was partly enlightened self-interest. PepsiCo’s long-term profits would be fatter if its customers were slimmer. Still, it was a jarringly candid admission.

Nooyi reclassified her company’s products into three categories: “fun for you” (such as potato chips and regular soda), “better for you” (diet or low-fat versions of snacks and sodas), and “good for you” (items such as oatmeal). She put money behind her proclamation, shifting resources from junk foods into the healthier alternatives and vowed to improve the healthiness of even the “fun” offerings.

Indra Nooyi CEO of Pepsico touring Pete's Fresh Market in Chicago. April 2015 Nooyi inspects a Pepsi display at a Pete’s Fresh Market in ChicagoPhotograph by Mark Peterson for Fortune

Such lofty ambitions didn’t play well among analysts, investors, and some co-workers. “She took the long view and was willing to take some heat,” says Doug McMillon, CEO of Walmart WMT , one of PepsiCo’s biggest customers. “If you were just running Pepsi for a quarter, you probably wouldn’t do what she did.” The heat intensified when the financial crisis hit and results tumbled. Market share in the company’s core business, carbonated soft drinks, fell almost two percentage points between 2006 and 2010, from 31.2% to 29.3%, according to Beverage Digest.

PepsiCo’s stock lagged the S&P and Coke’s shares. Many blamed the problems on Nooyi’s cuts in advertising and marketing for sodas and chips, as well as the $7.8 billion she spent to buy back Pepsi’s bottlers, which reduced the company’s return on invested capital.

In February 2012, with the stock languishing at around $60, Nooyi adjusted her formula. She pledged to restore marketing spending on soda and chips, buy back stock, and cut costs by $3 billion over three years. “The buck stops with me,” she said. Just prior to that, she replaced her head of beverages, whose rebranding of some major products had fallen flat, with Al Carey, the well-regarded head of Frito-Lay.

As if Nooyi wasn’t facing enough pressure, she soon had to contend with a major activist investor: Nelson Peltz, who took a stake in the company and began agitating for PepsiCo to undo its merger of Pepsi and Frito-Lay, just as Kraft KRFT had spun off Mondelez after a similar campaign by Peltz.

It was a distraction, to say the least. “To be honest, we don’t need activists to tell us what to do,” Nooyi says. She managed to largely fend Peltz off with a compromise: Earlier this year the two sides agreed on a “neutral” nominee to the board, former Heinz CEO Bill Johnson, an adviser to Peltz’s Trian Partners. Says Steve Reinemund, Nooyi’s predecessor as CEO: “She proved again that the strategy was right and tenaciously articulated it.”

Peltz’s campaign did impel PepsiCo to action. Says analyst Ali Dibadj of Sanford Bernstein: “There are a lot of things you can give her credit for from a strategic perspective, but I’m not sure the execution would have happened without the pressure from activists.”

One example was Nooyi’s reemphasis on marketing. At its core, a consumer products company is nearly as much about name recognition and image as it is about product. To boost PepsiCo’s brand awareness, Nooyi in 2012 hired Mauro Porcini, the head of design at 3M, as chief design officer. “A brand is like a person, like a celebrity,” says the Italian-born Porcini, resplendent in a flowered suit jacket and pointy slippers. “It needs to have a point of view.”

Under Porcini, design has become an integral part of product development and marketing. Today there are angular Pepsi “Axl” bottles, for example, created at the company’s funky Design & Innovation Center in Manhattan’s SoHo. Pepsi hosted a “Kola House” at Milan’s Design Week, a concept that it is now selling to other companies. It is peddling high-end clothes with Pepsi influences, and it is attempting to rebrand even its commodity products, such as Lay’s chips, as cool.

Then there’s the Spire, the iPhone-inspired rethink of the soda fountain machine. Pepsi was not first in this market—Coke was—but its latest version is beautiful, a simple white or black frame with a touch screen that offers as many as 1,000 flavor combinations. Unlike Coke’s version, which requires that restaurants buy additional new equipment, Pepsi’s is more about form than function, replacing what the customer sees but not requiring an expensive upgrade. The Spire, say executives, helped entice hot restaurant chain Buffalo Wild Wings to switch from Coke to Pepsi in 2013.

NOO06.15_Pepsi Style graphic Images Courtesy of PepsiCo

Another shift was the move to integrate the two sides of PepsiCo—drinks and snacks—more closely. “Snacks and beverages are bought together about half the time,” says CFO Hugh Johnston. “That’s a huge advantage for us.” Once virtually two separate companies with distinct management and cultures (Frito-Lay is based in Plano, Texas; Pepsi Americas Beverages, in Purchase, N.Y.), they’re now coordinating much of their marketing strategy. Says Rodney McMullen, Kroger’s KR CEO: “You don’t develop a snack plan or a beverage plan; you develop a promotion with all the Pepsi brands.”

PepsiCo has worked hard to improve its relationships with the giant chains that sell most of its products. Says 7-Eleven CEO Joe DePinto: “Our relationship has moved from somewhat transactional to one that has become highly collaborative.” The common ground began in 2011, when 7-Eleven suggested a few new Gatorade flavors based on its research. Pepsi agreed to produce Cool Blue Cherry Gatorade exclusively for the chain for six months; it sold 250,000 cases and became the top-selling flavor. Last year 7-Eleven had exclusive access to a thematically aligned pairing of snack and drink: Doritos Loaded and Mountain Dew Solar Flare. Likewise, a collaboration with Taco Bell in 2012—the Doritos Locos Taco—became the biggest product launch in Taco Bell’s history, with more than $1 billion in sales. Taco Bell is working with other PepsiCo brands, including Quaker’s Cap’n Crunch, to create Cap’n Crunch Delight doughnut holes.

Taco Bell And Pizza Hut Restaurants Ahead Of Yum! Brands Earnings FiguresDoritos Locos tacos and fire sauce packets at a Taco Bell restaurant.Photograph by Patrick T. Fallon — Bloomberg via Getty Images

Do consumers still crave things like Cap’n Crunch doughnut holes from Taco Bell? Some do—but suddenly a lot don’t. Nooyi predicted this, of course, but changing tastes are roiling traditional food and beverage companies.

Under the watchful gaze of chief scientific officer Dr. Mehmood Khan, I am sipping and snacking my way through the company’s newest offerings, developed inside Pepsi’s R&D department. Under Nooyi, R&D funding has doubled, and I’m sampling the results. In a conference room next to the company’s test kitchen, I taste—okay, inhale—such treats as a customizable Gatorade pod, tested by the Brazilian national soccer team, that mixes with water and delivers the proper electrolyte balance for your body’s needs; Naked Juice Kale Blazer, for green-juice devotees; Mountain Dew Kickstart, a fruit-flavored, lower-calorie drink; and Deep Ridged, a thick, super-crunchy potato chip developed first on a 3-D printer. “We have patents on the design, the cutter, the mouth experience,” says Khan. “This is multiple layers of IP.”

The science sounds impressive (as does the intellectual-property strategy). Yet the approach seems discordant in an era in which people crave fresh foods and artificial anything is under attack. Khan, a former endocrinologist specializing in diabetes, has been working hard on two primary goals: Invent hit products, and help make PepsiCo’s existing offerings healthier. Says beverage chief Carey: “I’ve told my team I want 90% of everything in development to have some improved health benefit.”

Healthier products continue to gain traction as millennials reject processed foods in favor of fresher fare. In the past five years, according to Credit Suisse analyst Robert Moskow, the top 25 food and beverage companies have lost $18 billion worth of market share—a stunning number. (See “The War on Big Food”)

The speed of change has accelerated so quickly that Target TGT CEO Brian Cornell, who used to work at PepsiCo, informed many packaged-goods suppliers in May that his company will spend less promoting their products. “The consumer trends are moving at a pace that I’ve never seen in my 30 years in the business, toward more natural and more real ingredients,” he says. “That’s happening everywhere.”

The most obvious shift is the turn away from sodas. The good news: PepsiCo’s diversification into products like yogurt means that soft drinks account for less than 25% of its sales. The bad news: PepsiCo is weaker in some categories, such as energy drinks, that are growing. Moreover, the definition of “healthy” is ever harder to pin down. “We’ve never seen the consumer as confused as they are today,” Nooyi said on a recent earnings call.

Case in point: Orange juice consumption has plummeted as consumers reject its high sugar; that has hurt PepsiCo’s Tropicana brand. Meanwhile Diet Pepsi has declined because people are also worried about sugar substitutes, in this case aspartame (the company announced in April it will stop using the sweetener). What hasn’t fallen as much? Mountain Dew, which is, yes, full of sugar and holds steady among young men. And sales of the company’s new cane-sugar cola rose an estimated 50% last year.

Mehmood Kahn at Pepsico headquarters. April 2015 PepsiCo’s chief scientific officer, Mehmood Khan, is looking to develop hit products—and healthier versions of old ones. Mountain Dew Kickstart is a version of the sugary high-caffeine soda with fruit juice in it.Photograph by Mark Peterson for Fortune

So while Nooyi was right to anticipate the health trend, her fun/better/good distinction may no longer make sense. For example, the company once viewed Diet Pepsi as “better for you”; few would agree with that opinion today. Nooyi herself was astounded by a recent encounter with a $9 bag of fried kale chips, which she called a “fat bomb.” “The consumer has turned the definition [of healthy] upside down,” she says. “If it is non-GMO, natural, or organic, but high in sodium and high in sugar and fat, it’s okay.”

These changing tastes are why Nooyi has largely abandoned her old categories and is increasingly emphasizing “corridors”: fruit and vegetables, protein, and carbohydrates. That’s a solid organizing principle—but it’s not a strategy.

For all of Nooyi’s moves to provide healthier products, most of PepsiCo’s profits still come from junk food—36% from Frito-Lay North America alone in 2014. “The thought process was that the ‘fun for you’ business would be the most challenged,” says analyst John Faucher of J.P. Morgan. “And that isn’t how it’s turned out.”

The company has made progress when it comes to making unhealthy products less so, removing some 400,000 tons of sugar from its drinks since 2006, and reducing the salt and saturated fat in Lay’s and Ruffles chips. There are also many healthier offerings, such as Quaker Real Medleys, premixed oatmeals that have less sugar and more fruits, nuts, and whole grains than prior incarnations.

Pepsi Co. Products Ahead Of First Quarter Earnings ResultsFrito-Lay snacks are displayed for sale inside a Royal Dutch Shell Plc gas station in Louisville, Kentucky on April 13, 2015.Photograph by Luke Sharrett — Bloomberg via Getty Images

Inventing a game-changing new product—one big enough to offset the decline in soda—has proved more difficult. Even though 9% of sales now come from offerings developed in the past two years, up from 7% in 2012, most are line extensions, such as Doritos Roulette, a bag of chips in which one of five is super-spicy. A few, however, are showing promise, particularly Kickstart, which hit $300 million in sales in its second year, apparently without cannibalizing Mountain Dew, now the No. 4 soda brand. Still, it’s hard to escape this conundrum: People want food with fewer substances in it. It’s hard to imagine that the words “Designed with a 3-D printer! All IP protected!” will attract today’s shoppers.

Nooyi may not have been able to control the shift in the marketplace, but she’s gone a long way toward shifting Pepsi’s culture. Once a decentralized place where local managers operated without much central interference, the company is now much less so—something that has made it much leaner but also much more top-down. That makes sense, because Nooyi is a top-down kind of executive. “The top needs to know all the pieces,” she says. “And the top better really get into the details. [Otherwise] you won’t know what questions to ask. You won’t understand these people when they come to you and say it’s too hard to do something.”

Nooyi is a notoriously demanding boss, though she notes, and others concur, “I wouldn’t ask anyone to do anything I wouldn’t do myself.” Perhaps because she began her career as a strategy consultant, Nooyi is very good at asking questions. She understands, deeply, the broader implications of every decision. But her passion for information, say several former executives, also sometimes slows major decisions, such as the development of Spire, which entered the market years after Coke’s Freestyle. “There are clear signs of analysis paralysis at that company,” says Bernstein’s Dibadj.

Nooyi is sophisticated, witty, warm, and loyal—she has called in top-tier doctors when an employee had a health crisis. She writes laudatory letters to the parents of executives who enjoy a big success or promotion. She champions women’s issues and isn’t afraid to talk about her kids, tell an off-color joke, or enjoy a sugary snack. (Speaking of which, were her daughters, now adults, allowed to drink Coke? “Absolutely, positively no,” Nooyi says. “And they wouldn’t pick it. They have great taste.”) Yet she can also be brusque and cutting, particularly with her direct reports. “Things are never, ever good enough,” says one former executive. “We used to call it the kick and the hug.”

Perhaps because Pepsi is known as a talent factory—or perhaps because Nooyi is so tough to work for—there has been significant executive turnover during her tenure. Virtually everyone once considered a potential successor has left the company. A few recent examples include Cornell, who came in from Sam’s Club to run the American food business and left less than two years later for Target; John Compton, the former president, who left in 2012 for a short stint running Pilot Flying J but didn’t return when it didn’t work out; and Zein Abdalla, his replacement, who retired abruptly in December. Other rising stars have left, such as Debra Crew, now at R.J. Reynolds Tobacco; Dawn Hudson, CMO of the NFL; and Eric Foss, now CEO of Aramark. “The people that like her are yes people,” says the head of one of the few remaining independent Pepsi bottlers. “It’s a culture of sycophants. It’s a shame, because she’s so smart.” (Responds PepsiCo communications chief Banner: “Indra has assembled a team of strong-willed, proven executives. Our culture encourages candid conversation and debate among the entire leadership team.”)

Starting to Catch Up?

Nooyi dismisses the notion of an executive exodus. “There are two kinds of people who have left,” she says. “One, those who get genuinely great jobs. Then there are other people who bubble up to the top, but the board doesn’t believe are [qualified to be CEO in the future]. I don’t believe we’ve lost anybody in PepsiCo who left for any other reason.” She also makes a point of showing me recent text messages from several departed senior executives as proof that her relationships with them endure. “Brian [Cornell] will send me an email every other week,” she says. “John [Compton] will send pictures. This is his daughter.”

It’s true that Pepsi’s talent development process is hugely admired. Carey, the U.S. beverage chief, travels with a leather-bound notebook in which he lists his top 100 executives and the next job each may be suited for. Nooyi leads 2½-day retreats every few months with 14 of the company’s high-potential executives. Each gets 35 minutes to talk about himself or herself. At the end Nooyi writes personal letters to the parents and spouses of each.

But the very top slot is more complicated. Nooyi and the board are encouraging anyone who moves into the top category to have experience in both beverages and snacks, and ideally a global assignment as well. This makes sense, yet few potential candidates fulfill all of the requirements. For example, CFO Johnston, the contender most often cited these days, has never worked overseas.

Director Daniel Vasella says PepsiCo hasn’t announced potential successors on purpose. “I don’t believe it’s smart for any company to designate a quasi-successor,” he says, “because that person often does not get the support anymore from others.” Adds Vasella: “We are in a situation where I have no inkling that Indra is thinking about leaving, and the board certainly wants her to stay for several more years.”

Indeed, Nooyi seems to be enjoying herself lately, which suggests she won’t go anywhere soon. She doesn’t turn 65 for another five-plus years. Still, Nooyi is prominent enough to be the subject of rumors she might be interested in a political post of some kind if Hillary Clinton is elected President in 2016. But that’s still more than a year and a half away, and Nooyi’s job is far from done. Says a CEO for a giant corporate customer of PepsiCo: “Can she and can the company make that pivot? Can it also continue to defend and nurture the current portfolio? That will be the ultimate final chapter.” Whatever happens, it’s a chapter Nooyi intends to write herself. 

A version of this article appears in the June 15, 2015 issue of Fortune magazine with the headline ‘Indra Nooyi Was Right. Now What?’