Democrat Gerald L. Baliles was elected governor of Virginia yesterday in a historic Democratic Party victory that swept the first black since Reconstruction and the first woman ever into statewide office in Virginia.

With all but 1 percent of the vote counted, Baliles, the former attorney general who closely tied his campaign to popular Democratic Gov. Charles S. Robb, won by a 55 to 45 percent margin over Republican Wyatt B. Durrette. Baliles, 45, ran strongly in most rural and suburban areas as well as urban sections, including populous Fairfax County, which Durrette had claimed as a stronghold.

State Sen. L. Douglas Wilder, 54, became the first black lieutenant governor elected in the South, defeating Republican state Sen. John H. Chichester of Stafford County by 52 to 48 percent with 99 percent of the vote counted.

Del. Mary Sue Terry, 38, of rural Patrick County led the Democratic sweep, rolling up a landslide 3-to-2 margin as she easily defeated the GOP's W.R. (Buster) O'Brien of Virginia Beach. With 99 percent of the vote counted, Terry amassed a 61 to 39 percent margin over O'Brien.

Baliles, standing with his wife and two children before a cheering crowd of about 2,000 at the John Marshall Hotel, praised his running mates and Robb, saying Virginians had "voted for the future."

Wilder, the grandson of a former slave, began his 16-month quest for the state's second highest office as a distinct underdog in a state with a long and bitter racial past.

"Many many years ago," Wilder recalled in his victory speech in the ballroom of the John Marshall " . . . I used to listen to political speeches as I would wait the tables on this floor and in this gallery. Little did I believe that one day I just might be your lieutenant governor . . . . "

The Democratic victory extended to the legislature where Republicans lost two seats in the 100-member House -- including one from Fairfax. The GOP also lost the Alexandria sheriff's race.

All three Republican candidates conceded before midnight before a supportive crowd of about 700 at the Marriott Hotel in Richmond.

Durrette, 47, a Richmond lawyer and former Fairfax legislator, conceded at 10:40 p.m., surrounded by his wife and seven children. "I can tell you honestly that I expected to come to this platform under different cicumstances," he said. "I want to congratulate Jerry and wish him well in the next four years . . . . The Republican Party of Virginia is strong . . . . It will survive this defeat."

"We think it means a new day for Virginia and a new day for the country . . . ," said Darrel Martin, Baliles' friend and campaign manager. "To have this happen in Virginia is an inspiration."

Wilder, an influential, 15-year veteran in the 40-member state Senate, ran well ahead of Chichester in urban areas with strong black voter registration and as predominantly white sections, including Fairfax County, Alexandria and Arlington.

"If my mother were here," Wilder quipped last night, "she would tell me, 'Don't let your head get too big.' "

The Baliles-Wilder-Terry victory enabled the Democrats to duplicate their dramatic 1981 sweep that broke a 12-year stranglehold by the GOP on the governor's office. The Democratic victories also were seen as a major boost for Robb, who had staked much of his political reputation on his ability to reshape the Virginia Democratic Party in a more moderate image.

Robb, who under Virginia law cannot succeed himself, has spent much of his four-year term in a determined effort to moderate the once-liberal image of the state party as he stressed fiscal conservatism and a concern for social issues.

Robb, a leader in a similar effort to moderate the image of the national Democratic Party, is expected to point to yesterday's election as an example of how the party can win national elections.

"We have made incredible history today," said Robert (Bobby) Watson, chairman of the state Democratic Party.

Democrats began lighting victory cigars before 8:30 p.m., shortly after television exit polls showed all three state Democratic candidates as likely winners.

The exit polls by Mason-Dixon Opinion Research Inc. of Columbia, Md., also showed that most voters who split the ticket aided the Democrats. A sizable number of voters said they voted for Durrette and Terry, but few said they voted for Baliles and any Republican, the polling firm said.

As they were in that election, blacks were a key element in the Democratic victories yesterday. Democrats pointed to key black precincts that voted overwhelmingly for their ticket.

For example, in one Norfolk precinct, Baliles outdistanced Durrette 1,120 to 33; Wilder trounced Chichester 1,170 to 18, and Terry beat O'Brien 1,047 to 45.

Dispirited Republicans gathered at the new Marriott Hotel about three blocks away as returns indicated their ticket -- nominated at a convention attended by 10,000 people in Norfolk last June -- was in serious trouble.

"We made a lot of mistakes," said state GOP Chairman Donald Huffman, wryly describing his black clothing as "a mourning suit." Huffman said the party "had a lot of difficulty getting our message out. The biggest thing that plagued the campaign were leaks. They damaged morale and the campaign."

Durrette's campaign throughout the fall was hampered by internal staff disputes over strategy and fund raising, much of which was reported by the news media.

Huffman contended "our philosophy is right, but we need to look at how we apportioned the money and ran the campaign." Some party members have complained that Durrette raised nearly $4 million but apparently spent less than half of that on crucial paid media.

At one point, Durrette staffers did an electronic sweep of their Richmond headquarters, but found nothing. Campaign leaders said they were convinced a "mole" was leaking information, but never singled anyone out.

After months of intense and expensive politicking, it was the rainy weather and flooding that may have had the greatest impact on voter turnout in many parts of the state.

Shortly before the polls closed, Democrats expressed concern over the weather and lower-than-expected turnouts in black precincts. "The low turnout in black areas is obviously going to hurt Democrats," said David Doak, a Baliles consultant.

"You would think there would be a little higher turnout in predominantly black areas with Doug Wilder on the ticket."

Doak said about 54 percent of eligible black voters had turned out at the polls in the critical Tidewater area, about 10 percentage points less than in the 1981 race for governor.

More than an hour before the polls closed, Durrette told reporters at his Richmond headquarters that he expected to lose the Roanoke and Tidewater sections of the state to Baliles, losses he blamed on the expected turnout of blacks.

The weather played havoc with election day get-out-the-vote efforts as state registrars scrambled to move 16 precincts because of flooding.

"In a few of the southwest precincts I heard nobody at all showed up to vote," said Don Harrison, a spokesman for Durrette. "And other people did, to find they had to go someplace else. Unless you put the ballots on an ark, you can't get the vote out down there."

Republicans said they expected the light turnout to benefit their candidates. "I hate to say somebody else's misfortune is our good fortune," said Durrette spokesman Steve Levitt.

"But near Roanoke, where Baliles has more support, people are more worried about saving their homes than voting."

The Virginia State Police executive protection unit stationed bodyguards with both Baliles and Durrette late yesterday afternoon, a step they described as a routine procedure.

Durrette said that for the first time in weeks he ate dinner with his family at their suburban Richmond home.

The three candidates on the Democratic ticket dined with Robb at the Executive Mansion.

Earlier in the day, all six candidates returned to their homes around the state to vote before gathering in Richmond. The Republicans were at the new Richmond Marriott and the Democrats were gathering several blocks at the older John Marshall Hotel.

The candidates for governor spent the final days of the campaign crisscrossing Virginia. While Robb, who under Virginia law cannot succeed himself, made several appearances with Baliles in Northern Virginia, Durrette paid a last-minute visit to the White House, hoping to boost his campaign with words of encouragement from President Reagan.

Reagan spoke at an Oct. 9 luncheon in Arlington that raised $500,000 for the Virginia GOP, but declined a standing invitation from the Durrette campaign to make a second campaign appearance in the state.