John L. Ray, who has been waging an energetic but badly trailing campaign to be mayor, yesterday dropped out of the District Democratic primary race and threw what support he has to City Council member Marion Barry.

Ray's endorsement, coming less than two weeks before the Sept. 12 primary election, was immediately hailed by Barry as an indication his campaign is picking up crucial momentum in what is thought to be a close, three-way contest among Barry, incumbent Walter E. Washington and City Council Chairman Sterling Tucker.

"We need a mayor who will take charge," said Ray, who appeared with Barry at a news conference at Ray's headquarters in Anacostia. "Marion Barry comes closest to my criteria."

Ray, a 35-year-old former government attorney making his first try at public office, had been hinting recently that he might not stay in the race to the end if doing so would make him "the spoller" who adversely affects the outcome.

Ray, who last week endorsed atlarge Councilman Douglas Moore in the City Council chairmanship race, said he expected to deliver between 10,000 to 15,000 votes to Barry, primarily from Wards 3, 5, 6, 7 and 8.

Saying his supporters wanted to see a change in city government and would now look to Barry to accomplish that change, Ray said he intended to make campaign appearances with Barry in a more personaleffort to transfer his support to him.

Ray, however, has never received more than a 2 percent voter-following in any of the various election polls taken so far, and it was unclear whether all or any of his backers could automatically be expected to follow his recommendation and switch.

Barry praised what he said were Ray's "talents and outspokenness" and said he welcomed him "to fight alongside me for the opportunity to bring to the city the kind of change we both want to see."

Pinning a campaign button on his newest supporter, Barry said with a grin that many of his backers - including some of his staff - had often said they would vote for John Ray if Barry were not running.

Both men said there had been no "quid pro quo" involved in Ray's endorsement of Barry, although Barry said they shared the same goals and would "talk after the election" about whether there is a place for Ray in the Barry administration.

"I'm not finished. I just got started," said Ray, who promised he would "be around and active" after the election and would "be there to lead the battle again" if Barry failed to do a good job as mayor.

Meanwhile yesterday Tucker's staff previewed two new television advertisements that his supporters said should help sharpea the issues in the final days of the campaign. The 30-second-long ads will be broadcast beginning today and will be supplemented later with at least three others, according to chief Tucker strategist Robert B. Washington Jr.

One of the ads depicts a shirt-sleeved Tucker standing in front of a resty barrel overflowing with garbage and saying. "The trash won't be cleaned off the streets without a mayor who cleans the tired blood out of city hall."

The ads stress leadership and zero in on the mayor, whom Tucker strategist Washington said appears to be gaining momentum in the campaign.

"We're not writing anyone off. The Tucker campaign takes nothing for granted," Washington said. "However, our best judgment, which is premised on hard analysis of polls and canvassing, would suggest that the election is a two-way race between the mayor and Sterling Tucker."

The mayor, who at one time was believer to be well behind both Tucker and Barry and who was the last formally to declare his candidacy, has shown "movement" in his campaign, Washington said. "Marion is either standing still or fading."

One new element in the Tucker ads previewed yesterday was a suggestion of a concern for possible voter apathy. "Some say this election doesn't matter, nothing's going to be changed," says Tucker' who then goes on to refute that premise.

The large number of undecided voters - as many as one third in some polls - has led some local political observers to believe voter turnout may be lower than anticipated.

The Tucker organization, like most others, is putting an emphasis on election day activities, and some observers believe he would be most hurt by a small voter turnout.

Lee Carty, Tucker's deputy campaign manager, acknowledged some concern about apathy. But she said it was coincidental that the reference to apathy was included in the ad.

Mayor Washington was endorsed yesterday by the political arm of the United Mine. Workers of America, in a move designed to buoy the mayor's election hopes and his efforts to win approval of a constitutional amendment granting the District full voting representation in Congress.

"Although we don't have any coal miners in Washington, we know that you have worked for and achieved many improvements for the citizens of Washington," said UMW vice president Sam Church Jr. at a morning press conference.