(Fortune Magazine) -- Around 4 p.m. on most afternoons, retired Wal-Mart executives gather in the men's-only grillroom of Pinnacle Country Club, the centerpiece of a gated community in Bentonville, Ark., that is home to some of the company's top managers. On the afternoon of Dec. 12, talk turned to the bombshell Lee Scott had dropped three weeks earlier. On the Friday before Thanksgiving, Wal-Mart's 59-year-old CEO announced his retirement after three decades with the company.

The timing of the announcement struck some former executives as odd. Wal-Mart tended to make management changes in January, after the holiday shopping season had drawn to a close and just before the start of its new fiscal year. "You don't announce that you're leaving your post before Christmas," one former vice president said.

The timing only heightened suspicions about what the real cause was. Had Scott's critics finally caught up with him? Or was he simply exhausted from years of doing battle with both external and internal foes?

When he took over as CEO in 2000, labor unions and environmentalists had painted Wal-Mart (WMT, Fortune 500) as retail's evil empire. Scott overcame an initial reluctance to engage these detractors, and he wound up transforming the company. But the untold story of his tenure is the internal war Scott waged as he dragged the company into the 21st century from its clannish roots. When a group of executives known as the "boots" - for their love of cowboy boots - threatened to divide management, Scott cleaned house during a 2005-06 purge, even though many of the boots had been friends of founder Sam Walton.

The final piece in Scott's remaking of Wal-Mart was grooming a successor, Mike Duke, also 59, who took the helm on Feb. 1. Only the fifth CEO ever to lead the company and the first to have never worked directly with Walton, Duke is a longtime Scott protege. (Scott hired him in 1995 as senior vice president of logistics.) As such, Duke is not expected to veer far from the course set by Scott.

Given his previous role as head of international operations, Duke is likely to expand Wal-Mart's presence in Russia and China to offset slowing growth at home and to focus on improving the nuts and bolts of store operations. The company is also trying to crack urban markets in the U.S., using Chicago as a test case.

"Mike will need to get comfortable in the job," Scott told Fortune during a recent interview. Scott's wood-paneled office at Wal-Mart's corporate headquarters, no bigger than a child's bedroom, is the same one Walton used. Scott remembers how it felt when he took over. Or as he puts it, "Moving into Sam Walton's office is intimidating. It's not a sense of power, but a sense of responsibility, the sense of being responsible for this legacy."

Regime change at Wal-Mart does not just affect the rank and file in Bentonville. It has a far-reaching impact on the business world because the company is a bellwether for the U.S. economy and for retailers everywhere. In the months ahead, Wal-Mart's new CEO will be wrestling with some of the same issues that bedevil the Commander-in-Chief - a drop in consumer spending and soaring health-care costs, to name two.

And managing Wal-Mart is not unlike running a small country. Its annual revenue of $400 billion exceeds Norway's GDP; it employs over two million people, more than the population of Philadelphia. It operates 7,000 stores worldwide and has held the No. 1 spot on the Fortune 500 for six of the last seven years. (Exxon Mobil (XOM, Fortune 500) beat Wal-Mart out for pole position in 2006 fiscal year sales.)

Scott's changes have finally started to pay off: Wal-Mart's stock was the best performer in the Dow Jones industrial average last year, rising 18%, and one of only two in the index to show gains. (The other was McDonald's (MCD, Fortune 500).) Although the company's shares, which recently traded at around $46, are lower than they were when Scott was named CEO, they have outperformed the S&P 500 over the past nine years. During Scott's reign, Wal-Mart's sales and profits have soared. When the company releases its 2008 results on Feb. 17, analysts expect Wal-Mart to report net income of roughly $13 billion - nearly a threefold increase over 1999, the year before Scott took charge.

Civil war in Bentonville

There were few outward signs of trouble when Scott took the helm in January 2000. But within the walls of the Bentonville headquarters, a civil war was brewing. The catalyst was Scott's winning the top job - upsetting another Wal-Mart executive, Thomas Coughlin.

The two men were from similar backgrounds, but their personal styles were the antithesis of each other's. Like many Wal-Mart executives, Scott did not have a privileged upbringing. The son of a gas station owner and a music teacher, he spent his early years working at his father's Phillips 66 station in Baxter Springs, Kan. His high school was so small that during football games he'd spend the first half playing clarinet in the band and the second half suited up on the field.

By the time he was 21, Scott was married with a child (he now has two sons) and living in a trailer while trying to finish college at Pittsburg State University in Kansas. (He says his grades improved after his wife told him she didn't intend to spend her whole life living in a mobile home.) After a stint at the Yellow Freight System trucking company, he joined Wal-Mart in 1979 as assistant director of logistics. In some ways Scott fit right into the company's bottom-line-oriented culture. According to one former associate, he was so frugal back then that he served guests generic Scotch.

Scott had been recruited by David Glass, a legendary Wal-Mart CEO who now owns the Kansas City Royals. Glass ran the company from 1988 to 2000 and he was famous for persuading Sam Walton, who thought "damn computer" was one word, to invest heavily in new inventory-management systems that would give Wal-Mart an edge for years to come. He was also instrumental in devising Wal-Mart's successful supercenter concept, which pushed the company squarely into the grocery business, where it took share from rivals such as Kroger's (KR, Fortune 500) and Safeway (SWY, Fortune 500).

Glass hired Scott after Scott walked into his office to complain that Wal-Mart would not pay a freight bill he felt was owed to his employer. Glass refused to pay the bill, but he was impressed with Scott's sincerity and drive. Glass eventually groomed Scott to succeed him.

As Scott rose through the ranks, he developed a reputation for being reserved, strategic, and sarcastic (he once joked with PepsiCo CEO Indra Nooyi that he was going to drop her products because she was slow to call him). His main rival, Thomas Coughlin, was ebullient and tactical. A former college football player at California State University East Bay in Hayward (where his wife was a cheerleader), Coughlin was larger than life not just in physical appearance but also in personality. He was beloved by rank-and-file employees, who saw him as one of their own.

When Scott was named CEO, Coughlin thought about leaving, but the Walton family persuaded him to stay. Hired in 1978, Coughlin had become a close friend of Sam Walton's, who died in 1992. Management was soon split between Scott and Coughlin, who had been named president of Wal-Mart's domestic stores. There were "friends of Tom's," called FOTs, and "friends of Lee's," or FOLs.

Like Coughlin, 59, who lives on a 2,500-acre Black Angus cattle ranch in Centerton, just west of Bentonville, many of the "boots" were free spirits who preferred Justins to Florsheims and jeans to suits. Most were old-school Wal-Mart employees who had helped build the company from the ground up. There were not a lot of college graduates among the boots - Scott once said they were unable to "conjugate a verb" - but they knew how to move merchandise. "If you were a boot, it meant you carried yourself with a bit of swagger," says one former employee.

Scott's group was more refined. Many of them live in French chateau-style houses that dot a gated community built around Pinnacle Country Club. In addition to Scott, residents include Duke, CFO Tom Schoewe, and Eduardo Castro-Wright, head of U.S. operations.

But the differences ran deeper than culture. The FOTs and the FOLs had radically different visions for the company's future. Scott was pushing to modernize how the company was managed, and many of the boots were resistant to change. Scott often complained that despite Wal-Mart's dominance, its management ranks did not resemble those of a Fortune 500 company. He wanted to recruit more college graduates and offer better training for senior management.

Scott and Coughlin clashed on issues large and small, including restructuring of store manager contracts and a plan to end layaway, which Scott supported and Coughlin opposed. (It was eliminated in December 2006 because of declining use and increasing costs.) Their differences came to a head during an October 2004 board meeting. Coughlin was frustrated that much of the meeting was spent discussing Wal-Mart's new environmental initiatives, rather than talking about business heading into the holiday season. After the meeting Coughlin, who didn't want to comment for this story, told Scott he was ready to retire and officially stepped down as vice chairman in January 2005, though he retained his board seat.

That might have been the end of it if Coughlin hadn't used a Wal-Mart gift card to buy contact lenses. The $100 card was part of an All Star program to reward lower-level employees. According to Wal-Mart, the home office was tipped off to Coughlin's use of the card when a salesclerk at the store called headquarters to inquire about the program. The home office employee could not understand why Coughlin would be using such a card and alerted corporate fraud, which launched an investigation.

Coughlin was forced to resign from Wal-Mart's board in March 2005, and the company accused him of stealing as much as $500,000 by filing fake expense reports and cashing in bogus gift cards. Coughlin has said that he used the money to finance covert anti-union activities. Wal-Mart says it knew nothing about such a program. Coughlin later pleaded guilty to wire fraud and tax evasion and served 27 months of house arrest. And in August, Wal-Mart agreed to pay Coughlin $6.75 million to settle a lawsuit it brought against him to void his retirement package, which according to regulatory filings was valued at $17 million.

The Coughlin investigation gave Scott cover to purge the boots, some of whom had committed ethical violations and others who were tarnished by association. At one managers' meeting, Scott told employees they had better choose sides - and choose wisely. "Make no mistake," Scott told them, according to two people who were there, "I can tell everyone what color underwear they're wearing." To those present, Scott's meaning was clear: He knew where people's allegiances lay, and he knew what they were up to.

While Duke was in the Scott camp - and even fired people when necessary - he also tried to heal some of the wounds caused by the in-fighting. To people who were upset about being forced to choose sides, Duke would say, "There may not be a right or wrong answer to this thing."

The atmosphere became so toxic for the FOTs that one afternoon when Edward Nagy, a senior vice president at the time, was eating lunch at his desk, Scott wanted to know why Nagy was eating alone. Nagy replied, according to a person familiar with the conversation, "Hell, Lee, you fired all my friends." Nagy, who left the company, declined to comment. Wal-Mart declined to comment about Coughlin or the purge.

"I'm not sure it was as much a fight between the factions as it was that Sam wasn't here anymore, and we had to make some of our own decisions," says Jack Shewmaker, Wal-Mart's former vice chairman and a director until last year. (Shewmaker, in fact, was once up for the top job but was beaten out by David Glass.)

Sam Walton may no longer have been around, but many longtime Wal-Mart watchers still wonder how involved Glass, Scott's mentor, was in the purge. He declined to comment, but this much is known: By 2006, Glass was no longer involved in the day-to-day operations of the company. He had stepped down from the executive and the stock option committees of the board, although he retains a board seat to this day. Scott continued to talk to Glass frequently during the shakeup, but according to sources, Glass did not play a role in the clashes with Coughlin and the old guard. "He trusted Lee" to do his job, says the source, "but he certainly appreciated the results."

Once many of the old-timers were gone, Scott changed the way managers evaluated their staffs and had them eliminate the bottom 20%. Many employees who made the cut had to re-interview for their jobs. Although the restructuring angered a lot of people, it was necessary to push the company forward. "There were people who took a picture of Sam Walton in 1992 when he died and decided that was what the company should look like going forward," says a former executive.

Even after he was out of the company Coughlin nearly succeeded in torpedoing his old nemesis. The court allowed Coughlin's lawyers to depose most of Wal-Mart's senior management, including Scott. At least one bit of embarrassing information was dredged up from the past: Scott's purchase of a 5.7-carat pink diamond for his wife from a Wal-Mart supplier, the Aaron Group. The price: $178,000, according to people familiar with the situation.

The diamond purchase was first made public in 2007, in a lawsuit filed by Julie Roehm, a former Wal-Mart marketing executive who was fired for allegedly having an extramarital affair with a co-worker and accepting free meals from an advertising agency that was vying for Wal-Mart's business. (A Michigan state judge dismissed Roehm's wrongful-termination suit, saying it should have been filed in Arkansas. Roehm has not refiled her suit.)

Scott's purchase drew a lot of publicity at the time, because several aspects seemed odd. For one, the Aaron Group is a maker of jewelry sold in chains like J.C. Penney and would seem an unusual choice for the buyer of a fancy diamond. Also, Wal-Mart has a famously strict ethics code that forbids executives from accepting so much as a coffee from suppliers. Even the perception of preferential treatment would not pass muster.

At the behest of Rhode Island state treasurer Frank Caprio, the Securities and Exchange Commission opened an investigation into potential lapses at Wal-Mart. (Through index funds, the Rhode Island state employee pension fund owns Wal-Mart shares.) One issue was whether Wal-Mart violated securities laws by not disclosing that Scott's son Eric worked for a company that does business with Wal-Mart.

Fortune has learned that the SEC found no wrongdoing. According to a letter dated July 5, 2007, the SEC informed Wal-Mart that it considered the issue closed. "We are not making any further inquiries in this matter and we do not intend to recommend any enforcement action," wrote Stephen Webster, the SEC's assistant regional director.

A new battle

The board backed Scott in his struggle against the boots, but once Coughlin had been dispatched, it grew impatient with Scott's unwillingness to handle Wal-Mart's deteriorating public image. Independent directors, including Jos Villarreal, a partner with law firm Akin Gump Strauss Hauer & Feld, and Roland Hernandez, former CEO of the media company Telemundo, joined with the Walton family in pushing for change. The family controls 43% of the company's outstanding shares - a block worth about $77 billion - and has three out of 16 seats on the board, including the chairmanship, held by Sam Walton's son Rob.

Orchestrating much of the criticism were the labor unions, which had tried since the late 1980s, with little success, to organize Wal-Mart employees. By 2005 the unions had changed their strategy. Union-financed watchdogs such as Wakeup Wal-Mart and Wal-Mart Watch started churning out damaging stories, and union officials recruited environmentalists and community organizers to join in the anti-Wal-Mart refrain. Soon consumers who had long benefited from Wal-Mart's low prices were questioning the retailer's practices. The company's runaway growth was stalling.

"The board wanted to be more proactive about getting our story out, but management stuck to Sam Walton's philosophy of, Do the right thing and let your actions speak for themselves," Shewmaker says. "As a result we waited five years too long."

Scott agrees that the board was way ahead of him on this subject. He says he didn't take its concerns as seriously as he should have, believing instead that the negative feedback was coming from blue-state elites who didn't shop at Wal-Mart and therefore didn't understand the money the company saved consumers. When asked how his approach changed over the past decade, Scott replies, "At one time in my career, if somebody criticized us, my first thought was, Why don't they like us? Or, What could we do to them? vs. now, when I think, Could the criticism have some truth?"

By late 2005, Wal-Mart was starting to fight back. It hired the Washington-savvy public relations firm Edelman and set up a political-style war room. Wal-Mart embarked on some green initiatives, introduced $4 prescription drugs for customers, and improved health-care coverage for employees. The company says that the number of uninsured associates on its payroll has decreased 40% to 78,186 this year, compared with 129,252 in 2007. Of the employees who are insured, about half are on one of Wal-Mart's plans, with the rest covered by other means, such as spouses or Medicare.

One simple illustration of how the company has used its size to create change is the impending switch to digital TV. Anyone without cable or satellite must buy a digital converter box. Wal-Mart, prodded by environmental groups, got the government to tie box rebates to energy-saving features, such as an automatic power-down switch, a move that the National Resources Defense Council estimates will save $900 million over the life of the boxes.

Winning over the left remains a work in progress. Wal-Mart is still facing the largest-ever class-action suit, which alleges the company discriminated against 1.6 million women. Wal-Mart is appealing the decision. In December the company agreed to a landmark settlement over wage violations, promising to pay at least $352 million (and possibly as much as $640 million) to settle 63 lawsuits that claimed it had forced employees to work off the clock.

And let's be clear: Wal-Mart, for all its changes, has not gone soft on organized labor. The company is opposed to a bill that could make it easier for employees to unionize - placing it squarely in opposition to the Obama administration and the unions. "The perception is that Wal-Mart has made all these improvements, but in fact, when it comes to labor and health care they've made almost no progress," says David Nasser, executive director of Wal-Mart Watch, one of the union-financed groups. For instance, Nasser says, the inflation-adjusted average hourly wage of a Wal-Mart employee is less today than it was in 2004. Wal-Mart says its average hourly wage, which was $10.86 last year, is similar to what other retailers pay.

A new commander

The timing of Scott's departure remains something of a mystery. Wal-Mart will not comment on it, but sources inside the company portray the changeover this way: Scott was tired. When he announced that he would take the entire month of May off in 2006 - a vacation he spent fishing in Longboat Key, Fla., where he owns a home - speculation swirled that his job was on the line. "What happened with Tom [Coughlin] was so intense that Lee needed to get away and get his head together," says a former executive. Says another ex-employee: "He was burned out."

In fact, two years before he took that leave, Scott had broached the idea of allowing employees to take sabbaticals. The plan never gained much ground given Wal-Mart's workaholic culture, but it remained something that Scott believed in. "Lee likes to lead by example," says Coleman Peterson, former executive vice president of Wal-Mart's people division, the company's folksy name for human resources. "That month off allowed him to show people it was okay to take vacation. It also gave him an opportunity to see how his team handled things in his absence."

By late 2007, Scott was thinking seriously of retiring. He broached the subject with board members in November during a meeting in Tokyo. By January 2008 another piece had fallen into place. Vice chairman John Menzer, 57, left the company, paving the way for Duke's ascension. As the board prepared to convene in Dallas for another meeting in November, Scott made it official. The weekend before the meeting, he called Rob Walton and other board members to inform them of his decision. A few days later the board elected Duke CEO.

By announcing his retirement in November instead of January, Scott felt he could give Duke control over budgets and strategic planning for 2009. (Duke would not comment for this article.) The timing also allowed Scott to exit before Wal-Mart was hit by the recession. In February, the company announced plans to eliminate over 700 jobs in Bentonville.

Given Duke's age - he is 59, the same as Scott - his term is expected to be shorter than his forerunners'. Waiting in the wings as possible successors are Eduardo Castro-Wright, 54, who runs U.S. operations, and Doug McMillon, 43, the former head of Sam's Club, who replaced Duke as head of the international division.

So exactly who is this guy moving into Sam Walton's old office? Duke received a bachelor's degree from the Georgia Institute of Technology in 1971. Not long after, he went to work in the logistics department of the May Department Store Co. in 1972, where he met Coleman Peterson, who would soon become HR director for Wal-Mart. When Scott told Peterson in late 1994 that he needed to hire someone who could one day replace him as head of logistics, Peterson told him he had just the guy. Scott took an instant liking to Duke, who soon became a confidant. The two belong to the same church, the Fellowship Bible Church, as do many other senior Wal-Mart executives.

In many respects, Duke fits the low-key Wal-Mart mode. A Georgia native, he and his wife, Susan, are known for their charitable work. Back in St. Louis, they became so involved with a local orphanage that one of the children lived with them for an extended period, until they arranged for her formal adoption by another family. Duke does have his indulgences, including a cherry-red Porsche 911 - although he is not audacious enough to drive it to the office. (Sam Walton considered fancy cars a no-no; the standard C-suite ride is an SUV hybrid.) Duke is also a golf lover and has a 13 handicap.

When Scott was named head of merchandising in 1995, Duke filled his place in logistics. One of Duke's first moves was to roll out a new distribution system called "one door per store," even though Scott had long opposed the idea. Under the old system, half-empty trucks made multiple store deliveries. Duke's plan called for consolidating shipments at the warehouse so that each truck would contain a full load of merchandise for a single store. The result was fewer trucks on the road and less docking space required at each store. In 2003, Duke was put in charge of Wal-Mart's U.S. stores and made head of international two years later.

Despite a "nice guy" reputation, Duke has shown he can make tough calls. Jeff Schomburger, president of Procter & Gamble's global Wal-Mart team, remembers his first meeting with Duke this way: Duke, who by then was head of U.S. stores, told Schomburger that P&G's profit contribution was uncompetitive and that Wal-Mart could not afford to increase its business with the consumer products manufacturer. "I was like, where is Mr. Nice Guy?" Schomburger says. A month later Schomburger was back with a plan that addressed many of Duke's concerns, and the two companies continue to do a lot of business together.

Duke is also a strategic thinker and risk taker. "Mike developed the strategy that Wal-Mart had to be in a position to win in every market they were in," says Maggie Gilliam, an independent retail analyst. That type of thinking led Duke to pull Wal-Mart out of Germany and Korea, two markets in which it had struggled for years. He also made the controversial decision to take control of Seiyu, the Japanese subsidiary, by raising Wal-Mart's stake to 95.1% from 50.9%. "Everyone was telling him to get out, but he felt there was a real opportunity for Wal-Mart to take costs out of the business once it had a controlling stake," says a person close to the company.

Despite his similarities to Scott, there is one important difference: Duke is known more for his people skills. "He's the kind of guy who will put his arm around you and help you through things," says Andy Bond, the head of Wal-Mart's U.K. division. Bond credits Duke with helping him avert a 2006 strike. "He told me that decisions are best slept on," Bond says, "and to try to look at things from other people's perspectives."

Much the way Six Sigma came to symbolize Jack Welch's approach to management at GE, Duke talks about "majoring in the majors." Given Wal-Mart's incredible size, it's his way of getting employees to focus on only the things that are big enough to make a difference. The idea even trickles down to business meetings. If managers exceed their allotted time by a few minutes, Duke will cut them off - his attempt to force them to prioritize.

***

On Friday, Jan. 30, his last day in the office as CEO, Scott sensed his time running out and found himself repeating the same phrase. "Whenever I called someone, I said, 'This is Lee Scott, the CEO of Wal-Mart,' because I knew it would be the last time I could say that," Scott says. He spent the weekend in Florida babysitting his 3-week-old granddaughter. Meanwhile, back in Bentonville, Duke moved his belongings into Scott's old office. (Scott now occupies a smaller space down the hall.) Scott will serve as chairman of the board's executive committee until 2011 and plans to continue his lobbying efforts on health-care reform and corporate green initiatives.

"Lee never entered the CEO job with a view to being there forever," Peterson, the former HR director, says. "He always believed there should be balance in life." Although he worked plenty of long days, Scott tried to leave the office by 5:30 to have dinner with his family, friends say. Once a colleague was in Scott's office around quitting time, and the two were deep in discussion when Scott simply got up, shut off the lights, and walked out. With similar abruptness, the Scott era at Wal-Mart has gone dark.



