The saga had a fairy-tale quality to it back in 1978: Charismatic outsider launches a long-shot campaign against an entrenched incumbent and scores an astonishing upset to become mayor of the nation's capital. Marion Barry was on his way to glory.

And what a ride it was. He seemed so suited to the District, this sharecropper's son, with his great political gifts, a talented staff and an economy that would keep the treasury brimming with hundreds of millions of new dollars. Barry transformed D.C. government, and his activist political agenda touched the lives of many of Washington's youngest, oldest and poorest residents.

But that was before his fast-lane appetites -- for alcohol, drugs and women -- undid him. In the time it took for the FBI to videotape Barry using a crack pipe in Room 727 of the Vista Hotel, a nearly 30-year career in public life went up in smoke.

Or did it?

"Most people have just seen a slice of my life," the mayor told Black Entertainment Television (BET) earlier this month. "They have not seen the totality of Marion Barry, the deep commitment I have for people, particularly the downtrodden, the sensitivity I have, and the brains that I have and what we've done for Washington.

"The Vista is what people probably saw the most of, the trial, but that was not the totality of me," Barry added.

It will be years before history judges the complex legacy of the complicated individual who was Marion Barry the mayor. Yet, as he prepares to leave that office next week after 12 years, interviews with more than two dozen community activists and Barry colleagues suggest he compiled a record of considerable public accomplishment, only to dismantle much of it as he self-destructed.

It was during Barry's first term (1979-1982) that he reached his full flowering as a chief executive, serving as an able and imaginative steward of District government in its awkward adolescence after the advent of home rule.

Building on the foundation laid down by Walter E. Washington, the District's first elected mayor in modern times, Barry showed that home rule could not only work, but in some ways work well.

He was also extraordinarily lucky, enjoying the prosperity of a boom that dramatically changed the skyline of the center city and propelled new office construction to record levels: 23 million square feet in 10 years, which helped triple real property tax revenue to more than $700 million annually.

The surge in revenue gave Barry the means both to fulfill his dream of creating a citywide safety net for the needy and to launch pet programs to keep his reputation bright with broad segments of the voting public. Nor did he stop there. With the power of the government's purse, he nurtured a growing middle class of black Washingtonians and opened the doors of government to interest groups long locked out of politics.

In short, Barry had the town by the tail. Because he knew every nook and cranny of the District's political house, because he showed such a flair for the mayor's job, because he had come up the hard way from the cotton fields of little Itta Bena, Miss., Marion Barry was a role model -- for blacks, hometown progressives and Democrats throughout the country.

"Across a spectrum of issues, he had the energy, commitment and faith to make government work for people," said James O. Gibson, a high-ranking city official during Barry's first term. "If he had gone after eight years, he would have been a hero."

But Barry did not go. The second term (1983-86), a time for consolidating the gains of the first, was marred by the departure of key aides and mounting evidence that Barry's personal habits were intruding on the public's business.

By the third term, he seemed too accustomed to the pleasures of power and deteriorated dramatically, having lost sight of his original mission in a haze of alcohol and drug abuse.

In his final year in office, struggling vainly for political salvation, Barry may have scarred the city by exploiting its racial divisions, leaving a legacy that some longtime residents believe will endure for years.

"Marion's embracing of racial polarization in the last stages of this term is a permanent scar and will forever keep people wary of the ethnic diversity of Washington," said Gibson, now the director of the Rockefeller Foundation's equal opportunity program.

Added Dwight S. Cropp, a former city Cabinet member and a Barry critic: "He has just about succeeded in destroying positive racial relations in the city, and he did it all for political gain. The negative impact on race relations in this city will take years to overcome."

Barry declined to be interviewed for these articles, but on numerous occasions he has denied trying to drive a wedge between blacks and whites. Yet a wedge there was; liberal whites who were instrumental in Barry's 1978 victory deserted him en masse as the fabric of his personal life and his public leadership unraveled.Imposing Fiscal Order

Like Sharon Pratt Dixon last month, Barry was swept into office after a come-from-behind win over establishment Democrats in the party's mayoral primary. And like Dixon, Barry inherited a daunting budget deficit.

Those who served during Barry's first term say his greatest accomplishment may well have been his installation of financial controls that enabled the city to get a handle on its budget.

"We did it," recalled Elijah B. Rogers, Barry's first city administrator. "We balanced the budget. We did the first audit in 100 years. And we achieved seven or eight years of reducing the accumulated deficit . . . . No one can take that away from us."

Rogers added that although resolving the budget situation was important in its own right, it also signaled that "minorities can manage a town of this size." In a city that until the early 1970s had been ruled by an often unpredictable Congress, one of Barry's lasting legacies was to show once and for all that the District could govern itself.

Barry also threw open the doors of government to many who had been shut out, including blacks, women, gay people and others who were essential parts of his winning coalition in 1978. Much of his outreach was motivated by politics -- Barry was forever trying to expand his electoral base -- but the onetime civil rights worker also seemed genuinely to empathize with others who had been denied access to power.

"Marion Barry was the one politician who was openly supportive of us and sought our support," said Richard Maulsby, one of the highest-ranking gay people in city government. On gay issues, he added, "Marion Barry is just head and shoulders above any other political figure in the country."

If Barry worked diligently to democratize government -- white- and male-dominated boards and commissions soon had black, Hispanic and women members -- he also took care to spread the fruits of government to the District's majority-black population. Cradle-to-grave social programs proliferated in the Barry years, and the nation's most aggressive program of minority contracting offered economic empowerment to a generation of black businesspeople.

"Marion Barry created a vibrant black middle and upper-middle class, using the governmental transfer of wealth," said Robert L. Johnson, the president of BET, who, as the holder of the city's cable television contract, was one of several entrepreneurs who benefited in the Barry era.

To Johnson, who became a close adviser to the mayor, one of Barry's most profound achievements was to "create a sense of pride in the town and a sense of power, to give blacks in Washington a fair shake at business opportunity and say, 'You've got a chance to be a player in the arena,' where before you wouldn't have been a major player."Remaking Downtown

Barry also forged a mutually beneficial alliance with former adversaries in the city's business establishment that, in a relatively short time, would alter the face of downtown Washington. Although the mayor in no way was single-handedly responsible for the makeover of Pennsylvania Avenue and the building boom in the center city, there is a widespread consensus that he helped create the atmosphere for redevelopment.

Max N. Berry, a former chairman of the Pennsylvania Avenue Development Corp., credited Barry with streamlining the permit process for new construction.

A longtime adviser and fund-raiser for Barry until he broke with the mayor during the final term, Berry recalled one "beam-hoisting" ceremony for a large office building on the avenue at 15th Street NW, where the president of the construction company paid tribute to the District government.

"He said, 'I want to tell you folks something: When we first heard about this project, I said let's not do it, because I heard the District government's terrible.' And then he said: 'I want to tell all you people that we've done buildings all over the United States, and this one was the fastest one we've ever done, in dealing with any kind of bureaucracy.' "

In the BET interview, Barry suggested that downtown development and projects such as the Washington Convention Center and the Frank D. Reeves Municipal Center -- which the mayor ordered built in a ravaged part of the city despite the objections of top aides -- represent his most concrete legacies.

"History will judge me and will judge my legacy by what we see here in Washington," Barry said.

Other kinds of judgments will be made as well, particularly on the final Barry years, when the mayor's administration seemed to grow more lethargic and relations with other institutions, notably Congress, soured. The bureaucracy "got tired, it got big and it got old," said Ivanhoe Donaldson, Barry's political mastermind, who left government in 1983.

While city agencies appeared unable to cope with a skyrocketing homicide rate, shockingly expensive public health problems and other issues, the mayor seemed headed, as he later put it, "down the road to personal destruction."

For those who respect what Barry did early on, what hurts most is the pain of the human tragedy in the mayor's decline and fall. As Annette Samuels, Barry's longest-serving press secretary, put it: "One of the tragedies of this situation is what we remember, what people remember, at the moment is the drug stuff, the depravation, the things that make you feel very sad.

"On the other hand, the man did some good," Samuels said. "The pain people feel doesn't take away the good."

Barry himself told BET that he will never again feel the pain he did in the final stages of his time in office.

"The roughest time in my life is over," he said. "I mean, it's gone."