The D.C. Board of Elections and Ethics ruled yesterday that Marion Barry Jr. did not have to resign from the City Council when he announced his candidacy for mayor, and may continue to hold office at least unitl the July 5 deadline for filing his nominating peititions.

The board's ruling, which was preliminary and did not mention Barry by name, was only a partial victory for him. He has filed a suit asking the U.S. District Court to declare invalid a city law that requires him to leave the council because of his mayoral candidacy.

Barry is one of three announced challengers in the Democratic primary for the mayoral post now held by Walter E. Washington, who is expected to seek reelection.

The congressionally enacted Home Rule Charter states that no elected official may run for another city office unless his present term expires before the start of the term for the other office. Barry's council term ends in 1981. The next mayor's term begins Jan. 2, 1979.

Under the strictest and most literal interpretation of that provision Barry would have been required to quit the council on Jan. 21, the day he announced his candidacy for mayor. Instead of doing that, he announced that he would go to court to challenge the law.

At the time there was no clear rule of the Board of Elections and Ethics defining when a person legally becomes a candidate.

The proposed rule drafted by Winfred R. Mundle, the board's general counsel, which was adopted yesterday, says a candidacy begins on "the same date as the deadline for filing nominating petitions . . ." This year, it is July 5.

The rule will become legally effective after it is reviewed by the board's elections administrator and its campaign finance director, and is published in the D.C. Register, giving the public 30 days to comment.

Another potential candidate to whom the new candidacy rule might also apply is council member Arrington Dixon (D-Ward 4), who is considering a race for City Council chairman.

The terms of two other council members who are announced candidates for different offices, Sterling Tucker and Douglas E. Moore, will expire next January, and thus they are not affected by the law. Tucker, like Barry, has said he will run for mayor, while Moore is seeking the council chairmanship.

In another action, the board ruled that votes cast for unqualified candidates for Advisory Neighborhood Commissions at the election last Nov. 8 cannot be counted in deciding any of the winners.

That action cleared the way for immediately certifying two candidates, Joe Isom of ANC 6A on Capitol Hill and Theodore Schell of ANC 3D in far Northwest, Yesterday's decision also is likely to fill at least eight of 29 ANG seats left vacant because of electoral uncertainties.