Virginia Lt. Gov. Richard J. Davis gave up his faltering Democratic campaign for governor yesterday and endorsed his rival, state Attorney General Gerald L. Baliles, abruptly ending a fractious party feud that Davis said threatened to take the Democrats "down the drain."

The dramatic turnabout by Davis, who had insisted he would take his fight to the party's June 7 nominating convention, came after a flurry of secret meetings among party leaders and transatlantic telephone calls with Gov. Charles S. Robb, who is on a Middle Eastern and European trade mission.

Davis' decision gives Baliles, 45, a chance to begin preparing for the fall general election while his likely Republican opponent, Richmond attorney Wyatt B. Durrette, still faces a bitter intraparty battle with Rep. Stan Parris of Fairfax.

Durrette, 47, has claimed enough votes to win the GOP nomination at its May 31 convention in Norfolk, but Parris has refused to quit the race and questioned Durrette's delegate strength.

At an emotional news conference at the Richmond State Capitol yesterday, Baliles stood at Davis' side as the 63-year-old former Portsmouth mayor announced "with some sadness, of course," the end of his million-dollar campaign and political dream to be the state's governor.

"All of you know that I have worked diligently, I hope, during the last several years to prepare myself to become governor," said Davis. He said he agreed during this week's negotiations with Robb and Baliles to become, instead, chairman of the party, a post he held for two years before running for lieutenant governor in 1981.

Davis acknowledged that his ef-forts to challenge as many as 750 convention delegates won by Baliles in the party's recent delegate selection caucuses had torn the party.

"Whether or not Dick Davis is governor is not really the important thing," Davis said, " . . . I really worked too long and too hard to build up the party to see it go down the drain . . . . " Davis said he wanted to avoid going "into some fractious, very divisive sort of thing that would make it difficult for Baliles to win in November."

Robb, traveling in Denmark, released a statement yesterday praising Davis. He said he had asked Davis to step aside and become party chairman in a telephone call Wednesday from Israel. Robb, who in 1982 became the first Democrat to win the governor's office in 12 years, cannot succeed himself under Virginia law.

Robb's action followed his own threat last week to abandon his neutrality and endorse a candidate to help resolve the Davis-Baliles delegate dispute. Robb said yesterday that "an objective analysis" of the delegate count showed that Davis could not win the nomination.

Alan A. Diamonstein, the current state Democratic Party chairman, said yesterday that Davis' withdrawal allows the Democrats to complete their statewide ticket six weeks before the party's convention.

State Sen. L. Douglas Wilder (D-Richmond) is unopposed for the party's lieutenant governor nomination and state Del. Mary Sue Terry (D-Patrick) is running unopposed for attorney general.

"Now that the ticket is formed, I'd like to see us take it around the state, maybe with Robb," said David Doak, Baliles' chief campaign consultant. "We have our house in order and they Republicans are still fighting. We ought to start campaigning now."

Many Virginia politicians said Baliles will be a tougher opponent for the Republicans than Davis, who they say is perceived as the more liberal Democrat.

Durrette, who lost to Baliles in the 1981 race for attorney general, has directed most of his campaign fire at Davis. Yesterday Durrette said he welcomed the challenge of confronting Baliles again. "I look forward to a rematch this November when the voters will . . . focus on the two of us at the top of the ticket."

Parris, who has warned that the Baliles victory would make Durrette more vulnerable in November, rejected suggestions yesterday that his own campaign is a threat to Republican efforts to unify the GOP. "There is no similarity between our situation and that facing Dick Davis," Parris said.

Democrats generally expressed relief yesterday that the party had avoided a bitter fight Sunday during a meeting of the ruling state central committee, which had been called to settle key procedural issues over the delegate dispute.

"There would have been a lot of bloodshed and a lot of hard feelings," said State Sen. Clive L. DuVal II (D-Fairfax), chairman of the Northern Virginia legislative caucus, who remained neutral throughout the fight.

Davis is expected to win election easily as party chairman at the Democratic convention. State Del. Richard M. Bagley (D-Hampton), the only announced candidate, appeared at yesterday's news conference and said he has agreed to run for vice chairman in charge of party operations.

Bagley, who is leaving the legislature, said he still intends to run for governor in 1989.