D.C. City Councilman Marion Barry gathered nearly 200 of his friends, neighbors and supporters in the hallway of a northeast Washington school building yesterday and formally announced his candidacy for the Democratic mayoral nomination in the Sept. 12 primary election.

Then the 41-year-old former D.C. School Board president and onetime street corner activist went immediately along the snow-lined sidewalks of E Street knocking on doors and shaking hands in a symbolic kickoff to his campaign.

"The issue in the election of 1978 is energetic leadership, leadership which is chosen by the people to do the people's bidding," Barry told the frequently cheering crowd inside the Kingman Elementary School at 14th and E Streets NE.

"I can provide that leadership," he said, "a leadership which will bring a new energy, a new visibility, a new capability to attract the talent, to reach out to the people and to mobilize this community to meet our needs."

Barry's formal announcement yesterday, which was partially aimed at removing uncertainty about his political future, opened the door to a long-anticipated legal battle over whether Barry can be a member of the City Council and a candidate for mayor at the same time.

According to city election law, no elected official can be a candidate for another city office if the term of the office sought begins before the end of the term the official is serving.

The person elected mayor this fall will take office on Jan. 2, 1979. Barry's present at-large Council term, for which he was chosen in 1976, does not expire until Dec. 31, 1980.

Barry said yesterday that, based on the advice of lawyers working with his campaign, he believes he can announce his candidacy, raise funds and campaign for mayor without having to resign. Only when petitions for candidacy are filed, Barry said, do his lawyers believe he has legally become a candidate. Primary election petitions may be filed as late as July 5.

Barry refused twice to give his view on the law's intention. But he did say he believes, "There is serious doubt about the constitutionality of the candidacy restriction." Thus, Barry said he plans to file a suit next week in court that will test the constitutionality of the provision.

"If the matter is not positively disposed of by July 5, 1978," Barry said, "I will resign my Council seat."

Shari B. Kharasch, chairman of the D.C. Board of Elections and Ethics, said yesterday that the board is still uncertain as to what constitutes formal candidacy and, beyond that, what should be done if a sitting elected official is found in violation of the law.

No similar incident has taken place in the four-year history of local elected government in Washington, she said. Kharasch said the board should reach a decision on the candidacy definition and removal procedures sometime next month.

Ivanhoe Donaldson, Barry's campaign manager, said yesterday the announcement was timed to help Barry gain campaign workers, secure promises of financial support and to end speculation that Barry is going to run for Council chairman.

For months, Barry was under pressure from congressional Del. Walter E. Fauntroy and other prominent city Democrats to run for chairman instead of mayor. Fauntroy and the others are supporters of the present Council chairman, Sterling Tucker, who informally announced his candidacy for mayor last week.

Tucker is older, more experienced and has already served as chairman, Fauntroy argues. In addition, Fauntroy said he fears that a Barry-Tucker showdown could divide and neutralize the political base which the three jointly built among the city's more active Democrats during the 1976 battle for control of the city party organization.

Barry has always said that he planned to run for mayor. In the heat of the persistent pressure to back down from that stand, he told The Washington Post in an Oct. 26 interview that he would run for mayor and had ruled out any race for chairman.

But doubt persisted among some city politicians and political observers, who remembered that Barry had toyed with the idea of running for Council chairman in 1974 and then decided instead to run for the lower post of at-large Council member.

"There's no turning back at this point," Barry declared in the October interview. Yesterday he took a verbal shot at those who had tried to discourage his mayoral candidacy.

"I've been asked by the political bosses not to run, to play along, to wait my turn, not to upset the applecart," Barry said. "However, I will not sit by and watch home rule turn into boss role. I will not see an administration anointed because it has been handpicked by a handful."

Barry sketched a multipoint platform and said detailed position papers would be presented later. He said he was in favor of a "fair tax system," better programs for senior citizens, a comprehensive city health plan and an over-all city housing plan.

He also said the city needs a better manpower program and he promised more hirings and promotions of women in city government.

At several points in Barry's nine-page prepared statement, he chided the current city government and the administration of Mayor Walter E. Washington as being inefficient and insensitive to the city's residents.He said city residents are most disappointed with the "defeated spirit and lack of enthusiasm" in city hall. "Many Washingtonians no longer expect anything from their government," he said.

Barry has been a prominent and influential member of that elected city government ever since its installation in 1975. "I am close enough to the government to understand how it works, but I have not been in it long enough to be captured by it," he said.

Campaign manager Donaldson said that at this point he considers Tucker to be Barry's major opponent. But if Washington should decide to seek re-election, the mayor would be the front-runner, Donaldson said. "The mayor is the incumbent and has a psychological edge no matter what the polls say," he said.

A Washington Post poll of 932 Democratic voters in the Nov. 8 School Board election showed Tucker to be the overwhelming choice of those interviewed in a three-way election, with Barry second and Washington third.

Barry said he has not decided whom he will endorse for Council chairman, but is at present leaning toward not campaigning with any chairman candidate as a "running mate." A final decision on that may not be made until June, however, Donaldson said.

The field of candidates for mayor at various stages of announcement includes about half a dozen persons. In addition to Barry, Tucker and Washington - who has not yet announced a decision on running but is expected by many to seek a second term - there is John L. Ray, a 34-year-old lawyer and former staff aide to the Senate Antitrust and Monopoly Subcommittee.

Ronald H. Brown, chairman of the board of the University of the District of Columbia, is also sounding out a possible candidacy. In addition, Charles Suel (Trummie) Cain, a D.C. school teacher who lives in Anacostia, has announced his candidacy.