Robert R. Merhige Jr., 86, a U.S. District Court judge who ordered Virginia schools desegregated and presided over major corporate litigation cases, died Feb. 18 at Virginia Commonwealth University Medical Center in Richmond after undergoing open heart surgery Tuesday.

Mr. Merhige’s unusually long tenure on the federal bench -- 31 years -- brought him many cases of national importance. He wrote the decision for a three-judge panel that threw out the appeals of Watergate figures G. Gordon Liddy, Bernard Barker and Eugenio Martinez after they were convicted of breaking into the office of Daniel Ellsberg’s psychiatrist.

He ordered the University of Virginia to admit women in 1970. He clarified the rights of pregnant women to keep their jobs. He presided over the trials of Ku Klux Klan and American Nazi Party members accused of injuring and killing members of the Communist Workers Party in Greensboro, N.C., in 1979.

No decision made him more unpopular than his orders to integrate dozens of Virginia’s school systems. He was widely considered the most hated man in Richmond in the early 1970s and required 24-hour protection by U.S. marshals. Segregationists threatened his family, spat in his face and shot his dog to death after tying its legs. Protesters held weekly parades outside his home. A guest cottage on his property, where his mother-in-law lived, was burned to the ground.

He told the Richmond Times-Dispatch last year that he was still amazed, disappointed and angry at the public reaction to his rulings.

“I thought people would say, ‘We don’t like the little S.O.B., but he’s following the law,’ “ he said. “That didn’t happen.”

University of Virginia law professor A.E. Dick Howard once called him “a trial court’s William O. Douglas.” He was known for his kindness and integrity and for brooking no delays or foolishness in his court, part of the Eastern District of Virginia known as the “rocket docket.” He once ordered a marshal to remove a man who had fallen asleep in the courtroom. The man, it turned out, was his father.

Mr. Merhige’s decisions tended to hold up on appeal. In 1988, the New York Times said Mr. Merhige’s rulings had been reversed less than 5 percent of the time by higher courts, an exceptionally low percentage.

He took an active role in getting lawsuits settled, imposing a $13 million fine against Allied Chemical for its pollution of the James River and Chesapeake Bay with the insecticide Kepone. But he also reduced the fine by $5 million after Allied set up an $8 million cleanup fund.

He presided over a complex bankruptcy reorganization plan for the A.H. Robins Co. in the Dalkon Shield case, in which control of the company would pass to American Home Products in exchange for its willingness to finance a $ 2.475 billion trust fund to compensate the IUD’s victims. That case delayed his retirement, although he went into semiretirement in November 1986. He retired in 1998 and joined the law firm of Hunton & Williams in Richmond.

Born in New York, Mr. Merhige attended High Point College in North Carolina and received his law degree from University of Richmond’s T.C. Williams School of Law in 1942.

He served in the Army Air Forces in World War II as a crewman on a B-17 bomber based in Italy. “It was no place for a guy who could read and write -- that’s how I describe [combat],” he told The Washington Post in 1985. “We hit Berlin. Salzburg. We hit Vienna so many times I felt like a commuter.”

Mr. Merhige practiced law in Richmond from 1945 until he was appointed to the federal bench in 1967 by President Lyndon B. Johnson.

Two weeks into his job, the new judge drew the first of the controversial cases that became the hallmark of his career. He ordered the release of black activist H. Rap Brown, who was imprisoned in Virginia after making an impassioned and militant speech in Maryland.

In 1968, Mr. Merhige ruled that the conflict in Vietnam was a war, whether or not it was a declared war. That ruling came in a case in which 96 Army reservists tried to avoid serving in Vietnam. Mr. Merhige denied their request.

On a tour of his memorabilia-filled chambers two decades later, a reporter noted that among signed photographs, which ranged from former FBI director J. Edgar Hoover to former attorney general Ramsey Clark, a copy of President Richard M. Nixon’s resignation adorned the mantelpiece. “I wanted that since the day he was inaugurated,” Mr. Merhige said.

Survivors include his wife, Shirley G. Merhige; two sons, Mark Merhige of Richmond and Robert R. Merhige III of Virginia Beach; a sister; three brothers; six grandchildren; and two great-grandchildren.