For the most part yesterday, Marion Barry was uncharacteristically cautious. Yes, he was the apparent winner of the critical Democratic nomination for mayor of the District of Columbia. Still, he noted, there are those 5,000 or so challenged and absentee ballots yet to be counted.

But then the self-proclaimed underdog, the candidate who uniformly trailed behind his two well-known rivals in a variety of polls, could no longer contain his delight and turned to a reporter and declared: "I am the mayor."

How Barry got to at least the threshold of being mayor - he still has to win the Nov. 7 general election - is a story of Barry's personal dogged determination and his ability to meld an unlikely coalition that Barry himself says is made up of the city's "scrappers."

There were the old civil rights activists who marched with Barry in the 1960s in the South, the 1970s feminists, the out-of-the-closet gay rights activists, the mostly white "urban pioneers" who have moved back to the city from the suburbs and a sprinkling of staid, old-line Washingtonians.

In short, it was a coalition that defied the maxim of Washington politics, that any winning candidate had to amass widespread support from the city's labor unions, the white establishment business community and black church-leaders.

But "Barry's Army," as he grew to call it, carried four of the city's eight wards and kept him close to his foes, Mayor Walter E. Washington and City Council Chairman Sterling Tucker, in the other four.

Before Tuesday's election Barry had said that in order to win he had to carry Ward 1 (inner city Northwest) Ward 2 (Foggy Bottom downtown, Shaw and Southwest) Ward 3 (affluent white Northwest Washington west of Rock Creek park) and Ward 6 (Capitol Hill and part of Anacostia).

As it turned out, that's exactly what he did.

Those wards formed the base of Barry's slender 1,118-vote margin over Tucker, pending the count of the challenged and absentee ballots. Barry, once a firebrand, fist-waving black militant, clearly captured the hearts and votes of a large percentage of whites who once viewed him as anathema.

Much of that support came in such largely white neighborhoods as Foggy Bottom, Chevy Chase, Georgetown, Capitol Hill, and Dupont Circle and integrated communities such as Southwest Washington and the ethnically diverse Adams-Morgan area.

But Barry said he built from his strength and that one of the keys to his victory was his ability to win large numbers of votes from black middle-and working-class people.

A Washington Post poll taken in late August showed Barry winning only 15 percent of the vote against Tucker and Washington in Wards 7 and 8, two areas with high concentrations of black residential neighborhoods. When the D.C. Board of Elections and Ethics finally finished counting the ballots after 3 a.m. yesterday, their tally sheets showed Barry third in both wards but with about 29 percent of the vote in both places and only slightly behind Tucker and Washington.

"I don't think I won with only white support," Barry said yesterday. "In fact, I dispelled the myth that Marion Barry has no black support."

Barry also did better than expected in Ward 4 and 5, two more voting districts with large numbers of back cent of the vote in Ward 4 and 27.9 percent in Ward 5, according to the unofficial returns.

Barry said that he had several personal low points during his nearly eight-month campaign, especially when the Post poll 10 days before the election showed him trailing with only 24 percent of the vote, seven points behind both Tucker and Washington.

A few days later, Barry said he was especially hurt when his minister and longtime intimate friend, the Rev. David Eaton of All Souls' (Unitarian) Church, decided after lengthy fence-straddling to endorse Tucker.

But Barry's advisers managed to turn Eaton's last-minute decision to endorse Tucker along with Ward 3 City Council member Polly Shackleton into a campaign plus.

Barry and his advisers held out the vague prospect to Tucker and his aides that Barry might drop out of the race and endorse Tucker after meeting with Eaton. Barry agreed to a meeting late Thursday night and as a result the Thursday afternoon endorsement press conference was postponed. But Barry never showed at the late-night rendezvous, an aborted gathering that Washington later dubbed "midnight maneuvers."

Some of Tucker's aides said yesterday that the caper was a disaster for their candidate. "It was absolutely appalling," said Lee Carty, Tucker's deputy campaign manager.

But Barry said such personal setbacks only strengthened his will to campaign harder.

"I never though about withdrawing," he said. "The civil rights movement had toughened me to go all the way against the odds. I have too much personal pride to withdraw."

Barry said his key to winning was his personal campaign style, which included large doses of neighborhood handshaking treks, countless coffee klatches and living room fund-raisers.

"I've been on blocks and streets where most people have never seen a candidate for mayor in their life," Barry said. "Passing sound trucks and motorcades don't impress them.

"People underestimated me and my campaign," said Barry, who has twice won election to an at-large seat on the D.C. City Council. "All the big institutions were against me" - labor, business and the incumbency of the mayor.

"That's a heck of a thing to overcome," he said.