District of Columbia gay rights advocates parted company Tuesday night with an old political ally, Mayor Marion Barry, and endorsed Sen. Edward M. Kennedy's bid for the Democratic nomination for president Barry is supporting the reelection of President Carter.

On a 28-to-27 vote -- with the losers favoring no endorsements at all -- the Gertrude Stein Democratic Club voted to support Kennedy's campaign in the May 6 D.C. primary with a $2,000 contribution and 200 volunteers. The Stein Club is the city's major gay rights political organization.

In past city elections, homosexuals have been one of the most politically productive special interest groups, especially in their ability to muster energetic campaign volunteers and turn out voters on election day. Gays played an integral part in Barry's surprise victory in the decisive 1978 Democratic mayoral primary.

In November, California, Gov. Edmund G. (Jerry) Brown Jr. appeared at a Soutwest Washington gay disco and became the first major candidate in the 1980 campaign to make an open, personal appeal for gay votes.

But Brown received only a handful of votes in the first of two ballots cast Tuesday night, even though he is considered the Democratic candidate with the longest standing record of support for gay rights.

Stein Club spokesman Jim Zais said yesterday that Brown got few votes from club members because, "They don't think Brown is a viable candidate, certainly not in the District." City political observers expect a head-on clash between Carter and Kennedy in the primary.

Zais said support for Kennedy was based primarily on the fact that Kennedy's representatives in the District of Columbia include politicians who have long been favorities with the gay community, including City Council members John Ray (D-At Large), Betty Ann Kane (D-At Large) and Nadine Winter (D-Ward 6).

At the November fund-raiser at which Brown appeared, Kennedy sent a representative who read a statement saying Americans should be concerned when persons are discriminated against on the basis of sexual preference.

"There is some ambivalence about the Kennedy endorsement because he clearly hasn't been outspoken," Zais said, explaining why so many persons had been opposed to any endorsement. "Kennedy has been in the Senate for 17 years and he hasn't done anything [for gays]. His gay rights position is very young."

Already, many prominent individuals in the liberal, odds-and-ends coalition that swept Barry into office have climbed aboard the Kennedy bandwagon, leaving Barry with the prospect of having to campaign against and without the help of many of his old allies in the May 6 primary.

Zais said yesterday that many gays did not believe that differences over presidential preference would result in a permanent split, however, because they feel Barry is supporting Carter only to ensure White House co-operation in D.C. affairs.

"There is a feeling," Zais said, "that Barry is only behind Carter for the interests of the District, and is not really a Carter supporter at heart."

"city Council Chairman Arrington Dixon, who also had strong support from gays in the 1978 primary and is a full-fledged advocate for Carter's reelection, appeared at Tuesday night's meetig on behalf of Carter.