One of the nastiest political campaigns in recent Virginia history is ending with a new poll showing Republican Senate candidate Paul S. Trible Jr. with a narrow three-point edge over Democrat Richard J. Davis. Spokesmen for both campaigns said yesterday that the race remains too close to call.

The Trible-Davis contest, marked by a recent flood of direct mail attacks and negative broadcast advertising, is considered among the tightest in a local election lineup that includes races for governor and the Senate in Maryland, mayor of the District of Columbia, and congressional and legislative seats throughout the Washington suburbs.

Final newspaper polls released yesterday showed Maryland Democrats Gov. Harry Hughes and Sen. Paul Sarbanes with comfortable leads over their respective Republican challengers, Robert A. Pascal and Lawrence J. Hogan. In the District, Mayor Marion Barry is anticipating a landslide victory by margins of 8 to 1 or better over a little-known Republican challenger, E. Brooke Lee.

While all eight incumbents are favored in the Maryland congressional elections, Democrats in Virginia are optimistic about capturing two to three of the nine Republican seats in the state's congressional delegation.

One of the Democrats' best chances is in Northern Virginia, where Republican Rep. Stanford E. Parris is being challenged by Herbert E. Harris, the man he beat two years ago.

The final election poll in Virginia, published in today's editions of The Richmond Times-Dispatch, has Trible, a Newport News congressman, ahead by 43 to 40 percent in the race for the seat of retiring independent Sen. Harry F. Byrd Jr., a lead that is still within the poll's three percentage point margin of error. Sixteen percent of those polled were listed as undecided.

Democrats reacted to the figures with disbelief yesterday, claming that their most recent poll by Democratic pollster Peter Hart has Davis ahead by three points statewide.

The disparity between polls was more glaring in Northern Virginia where The Times-Dispatch poll has Trible ahead by two points. Davis campaign officials said their polls show Davis leading in the Washington suburbs by 17 points.

Trible's camp, however, said The Times-Dispatch's numbers are almost identical to their own, which show undecided voters moving their way. "There's been gradual and steady movement," said Trible campaign manager Judy Peachee. "I'm cautiously optimistic."

The campaign's negative tone has sharpened in the past week with new direct mailings by New Right groups on behalf of Trible and tough radio ads from the Davis camp.

Davis campaign officials pointed yesterday to what they called last-minute "lies" and "distortions" -- a National Rifle Association letter to 60,000 Virginia members attacking Davis on gun control, a mailing by the Rev. Jerry Falwell accusing Davis, the state's lieutenant governor, of having a "bigoted opinion of the Bible-believing people of the Old Dominion," and a Trible campaign letter signed by Rep. Henry Hyde (R-Ill.) saying Trible's defeat would be "a victory for the pro-abortion forces."

"It's clear that after four months of trying to position himself as a responsible conservative slightly to the right of center, he [Trible] is now going all the way to the New Right," said Davis campaign manager James Carville.

The letter by Hyde was clearly aimed at shoring up Trible's support among anti-abortion groups, who angrily criticized him after he publicly refused to endorse a Constitutional amendment banning abortion.

Hyde, a national hero to the movement, hints in the letter, sent out under Trible campaign stationery, that Trible's mind could be swayed. ("I have not given up on ultimately convincing him . . . ," Hyde writes.)

A Trible spokesman emphatically denied yesterday this meant that Trible was backing away from his opposition to the amendment. "That letter says more about Congressman Hyde's desire to arm-twist than it does about a change of position," said campaign spokesman Neil Cotiaux.

For its part, Trible's campaign complained about a Davis radio ad, prepared by Democratic media consultant Robert Squier, featuring a 30-second tape-recording of Trible stammering and groping for words as he attempts to answer a question about his "proudest" legislative achievement. "I think people couldn't believe that anybody would put that mean a spot in Virginia," said Trible manager Peachee. "I think everbody's been shocked by it."

The personal attacks have marked the Trible-Davis campaign almost from the outset, virtually obscuring debate over economic and national issues and turning the contest into what many believe is one of the most bitter in Virginia in years.

"I think it's been terrible," said Fairfax County state Del. Vincent F. Callahan, the Republican leader in the House of Delegates. "Campaigns in the state seem to be degenerating . . . . It seems to be the influence of the political consultants who I think are parasites on the political system."

During the final weeks, Davis and Trible have stuck almost exclusively to economic themes in their campaign talks. Davis, a 61-year-old former Portsmouth mayor, has continually ridiculed Trible's exhortations to "stay the course." Trible, 35, attempted to link Davis to Sen. Edward M. Kennedy and the "bankrupt tax and tax, spend and spend" policies of the past.

Trible, whose campaign coffers have been filled by hundreds of thousands of dollars from political action committees, is outspending Davis by a 2-to-1 margin.

The final days have also seen Democratic Gov. Charles S. Robb emerge as a central figure in the Davis campaign, a development that has been linked to the governor's reputed desire to boost his standing nationally as a potential 1984 vice-presidential candidate.

During the past two weeks, Robb has traveled virtually side by side with Davis throughout the state, serving as point man for campaign attacks on Trible's credibility and integrity. At a Richmond luncheon for conservative supporters of Davis this week, Robb's voice was filled with sarcasm as he engaged in a mock reading of an allegedly misleading Trible fund-raising letter. "I'm not talking about excesses, I'm talking about premeditated factual inaccuracies," declared Robb. He went on to hail Davis as a man who "epitomizes the fiscal responsibility and political integrity" of Byrd, who is retiring after 17 years in the Senate.

In fact, the surge in Democratic hopes this year traces partly to the rejuvenation of the party after last year's sweep of statewide offices, a triumph led by Robb that broke a 16-year record of statewide Democratic defeats.

Nowhere has the Democrats' resurgence been more apparent than in the state's congressional races, where the party has fielded an unusually strong crop of candidates--from state legislator Norman Sisisky, a wealthy Pepsi-Cola bottler who is expected to put $250,000 of his own money for his campaign in the southeastern 4th district, to retired General Electric executive James Olin, now in a close race for an open seat in the Roanoke-based 6th district.

Another Democrat drawn into the field this year is state Sen. Frederick Boucher, a 36-year-old lawyer from Abingdon, who is given an outside shot at ousting veteran Republican incumbent William Wampler in the mountainous "Fighting Ninth" district in the far southwest.

Robb's victory "showed the type of coalition that was available to candidates," says Democratic state party chairman Alan Diamonstein. "It gave people encouragement to run."

A bright spot for the Republicans may be the 100-seat House of Delegates where all candidates are running for the first time this year in single-member districts, including a number of newly created suburban districts. Republicans are fielding a record high of 66 candidates this year. "We are definitely going to gain some ground," said state GOP spokesman Clayton Roberts. Privately, GOP leaders are talking about increasing Republican numbers by between two and six, up from the current 33.