Virginia's Democratic-controlled legislature today wound up a year-long ordeal over redistricting by approving a plan that many legislators say hands a resounding election year victory to an unlikely alliance of the state's blacks, civil rights groups and Republicans.

Under pressure from a U.S. court and the Justice Department, which has twice rejected earlier proposals for alleged racial discrimination, an exasperated General Assembly agreed to a new map for the House of Delegates that concentrates black residents in the Hampton Roads area into a handful of urban districts, thereby boosting the chances for the election of two, and possibly three, new black lawmakers this fall.

Although 19 percent of Virginia's population is black, there are only four blacks in the 100-member House and one in the 40-member state Senate.

Civil rights groups that had carried the redistricting fight from the beginning were exultant. "This is a 99.5 percent victory in a year-long fight," said Judy Goldberg, lobbyist for the American Civil Liberties Union.

Henry Marsh, the black mayor of Richmond and lawyer for the state NAACP, said his group would support the new plan before Justice and in federal court. "We've achieved what we set out to do," he said.

Legislative leaders predicted the plan would have little difficulty winning approval from either Justice or the courts.

In drafting the latest plan, the Democratic leadership reluctantly was forced to create more house districts that are mostly white, conservative and potentially Republican-- a remapping that many lawmakers said presages a fundamental shift in the ideological and partisan makeup of the state legislature over the next decade. Many of the GOP's gains were apparent in earlier House plans, but it was not until today's legislative action was completed that some Republicans were willing to claim victory.

"They've the Democrats gone though this whole process without reaping any political benefits," said Del. Clint Miller (R-Shenandoah.) "Now we've got pockets of Republicans that didn't even exist before, who used to live in districts where they were swamped by the inner city vote. The real bottom line winner in this is the Republican party."

State GOP party spokesman Neal Cotiaux, calling the redistricting finale a "serendipitous situation," predicted that the Republicans, who currently hold 33 seats in the House, will be able to pick up at least six and possibly as many as 12 new ones in the fall. Miller was even more optimistic, forseeing the first GOP takeover of a Virginia legislative chamber since Reconstruction.

"I'd say that, unless Reagan falls on his face and there's a deep depression or there's a tremendous botch-up like Watergate, we'll have a majority in the House of Delegates within the next five to six years," said Miller.

Surprisingly, the House Republicans ended up voting in a block against the final plan today, arguing that a rule by the Democratic leadership blocked them from seeking even more changes. The new GOP advantage is perhaps the supreme irony of a torturous debate over redrawing House boundaries that required 14 special sessions, a cost of more than $1 million and five failed redistricting plans.

The central issue throughout the debate was the demand of civil rights groups, later backed up by former governor John N. Dalton, a Republican, and the Reagan administration's Justice Department, for the abolition of citywide at-large districts that have protected senior white Democratic incumbents and, according to the critics, diluted black voting strength.

In today's special session, the House Democratic leaders, saying they were fed up with the whole process, finally agreed to eliminate the last at-large holdout in Norfolk, carving up the state's largest city into five single-member districts. Two of the new districts are majority black, and another contains the homes of two popular Democratic Delegates, Edythe Harrison and George Heilig.

Other Tidewater Democrats also were jettisoned. The new House lines throw Del. L. Cleaves Manning, a 14-year house veteran from Portsmouth and chairman of the Counties, Cities and Towns Committee, into a district that is 60 percent black. In Hampton, while creating another black majority district, the Democratic leadership placed junior Democrat Thomas Glascock into the same predominantly white district as Richard Bagley, chairman of the powerful House Appropriations Committee.

"My alternatives at this point are to run against Richard Bagley, to move or to go back to practice law and being an average citizen," said a dejected Glascock on the floor today. "Right now, I'd say the last alternative doesn't seem too bad."

House Democratic leaders tried to paint the brightest possible portrait of what they privately admitted was a dismal situation. Their last-ditch defense to dissatified members of their own party was that the final product would placate Justice and thereby was the only sure way to put the redistricting dilemma behind them.

"I'm well aware that this does people in this House harm . . . But this is the only way the house can redraw its boundaries," Del. Claude Anderson (D-Buckingham), chairman of the House elections committee told his colleagues on the floor.

The upshot of the plan will be a more conservative legislature that will be hostile to black issues, said Del. Dorothy McDiarmid (D-Fairfax). "What we've doing is ghettoizing whites and blacks into separate areas," she said. "To me, we've been behaving in a very civilized manner in communicating between the races. But now we're going to be polarized."

The civil rights groups that had pushed for single-member districts say the alleged "communication" is an illusion that easily was shattered during the 1982 session. Conservative Democrats, often joined by Republicans, defeated virtually every bill of interest to blacks, including a state holiday honoring Martin Luther King and a measure banning state tax exemptions for segregated private schools. They passed another bill forbidding localities from enacting minority set-asides. Some black leaders called it the worst legislative session on racial issues in years.