Long after the polls had closed and the winners of the other 1981 political races in Virginia had been decided, the campaign headquarters of the Democratic candidate for attorney general was in a near-frenzy as the year's closest race hung in the balance.

In the midst of the ringing phones and the shouts of friends and supporters who had converged to hear the latest returns, one person was conspicuously absent: the candidate. Behind a closed door, in a small office down the hall, Gerald L. Baliles sat calmly with his feet propped up on a chair, immersed in a volume of Virginia statutes on election recounts.

To those familiar with Baliles' intellectual bent, passion for being prepared and powers of concentration, it was no surprise to find him there. He is, after all, the kind of person who carries a book entitled "Great Documents of the Western Civilization" in his briefcase while making campaign appearances and refers to such entries as Louis XVI's letter to the king of Prussia as "amazing stuff."

He has been known to memorize the names of as many as 150 supporters at a political gathering and recite them all back to them. A meticulous planner, he amazed one political scientist with a blueprint for a campaign that factored in every conceivable contingency fully a year before the first critical test took place.

The studious style and careful analysis have served Baliles well in his nine-year political career. Partly because he has chosen his opportunities so carefully and prepared so thoroughly, he won three terms as a state legislator before embarking on his underdog -- and ultimately successful -- campaign for attorney general.

Now Baliles, 44, is locked in a close contest with Lt. Gov. Richard J. Davis for the Democratic nomination for governor. A crucial, perhaps decisive, test will come this weekend when Democrats hold a series of mass meetings across the state to choose delegates to the party convention June 7.

Although the race has not been distinguished by differences on issues, Baliles is generally seen as a moderate conservative candidate, somewhat to the right of his opponent. Both admirers and critics regard him as controlled and hardworking, a politician who has approached his jobs in government with utmost seriousness and who has accomplished much of what he has set out to do.

"Thorough, conscientious and very rational," said his wife Jeannie. "That's the way he approaches everything."

Where the two groups differ is in whether Baliles has produced any major accomplishments during his political career and in whether he is just careful or so afraid of controversy that he would shy away from any initiatives as governor.

Baliles agreed that he is cautious, "if by cautious one means that one does his homework," but he said he is "not reluctant to make decisions."

His type of homework is an exacting business. As a legislator trying to put through a bill to allow right turns on red lights, for example, he developed detailed estimates of how much gas is wasted by the idling cars -- a "painstaking" amount of work for a minor bill, said Sen. Virgil H. Goode Jr. (D-Franklin), a supporter.

Though his wife said "I would not describe him as a complete perfectionist," Baliles comes close in his attention to detail.

A misplaced apostrophe in a glossy booklet that outlines his campaign positions "was like something sent to torment him," said Darrel Martin, his campaign manager. One political mentor loved to tease him: "It only takes 51 percent."

"He just doesn't do anything unless there's an awful lot of preplanning that goes into it," said Larry Framme, a Richmond attorney and friend. "I think he will try to avoid situations where he will have to shoot from the hip. He will go to great pains to keep from getting into it."

Above all, Baliles seems to pride himself on being a thinking politician. At a campaign stop in Roanoke where a railroad firm repairs its locomotives and cars, he peppered his hosts with questions about inventory control, overhaul time, accident-free rates. In describing himself, he chooses "intellectually curious" and "fascinated with concepts" first.

His seriousness dates to his boyhood on his grandparents' modest farm in Patrick County south of Roanoke near the North Carolina border, where Baliles grew up after his parents separated. He recalls his grandparents as strict disciplinarians and said he was allowed little idle time.

By the time he was in college at Wesleyan University, he had perfected habits of self-discipline and a prodigious appetite for hard work that keeps him going on five hours of sleep a night for as long as six or seven weeks at a stretch. His long hours then were dictated partly by necessity: he had to wait on tables in his fraternity and take other jobs to supplement his financial aid.

Before a microphone, his lack of flash is striking and his words seem staged and stiff. "I consider Jerry to be the most intelligent officeholder in Virginia," said Larry Sabato, a political science professor at the University of Virginia. But he added, "I think he's a terrible speechmaker and speech writer."

One on one, Baliles loses his dull finish and comes across as easygoing and personable. He laughs easily and makes a point of remembering details about individuals: who has been sick, who just got elected to the school board.

A certain reserve stays with him, though, even in relaxed situations. He keeps his tie properly in place while others have loosened their collars, and he keeps his emotions well under control. "Really excited?" asked his wife. "I don't think I've ever seen Jerry really excited. He's not that type of person."

As both a legislator and as attorney general, he has earned high marks for effectiveness, according to a Norfolk newspaper's polls of legislators, lobbyists, administration officials and reporters.

As attorney general, he is credited with drastically reducing the amount of time to issue opinions, reorganizing the office and keeping a professional distance between his political views and his legal advice and decisions.

One of his main efforts was to push Gov. Charles S. Robb's 1982 legislative crime package. The results included tighter control of prescription drugs, a broader range of evidence allowed in wiretap cases and the advent of regional and multijurisdictional grand juries to help investigate drug rings.

He established two units to investigate Medicaid fraud and to collect debts owed to the state, which he said saved millions of dollars.

Sen. Dudley J. Emick Jr. (D-Botetourt) is one of a number of legislators who describe Baliles as "outstanding" in the job. Del. Ralph L. Axselle Jr. (D-Henrico) said Baliles "set a standard for the quality of service the attorney general should provide."

Thomas R. Morris, a political science professor at the University of Richmond who has studied the attorney general's office, is somewhat less enthusiastic. While Baliles has continued a general trend of professionalizing the office, Morris said, "I don't sense that he has initiated major innovations during his term."

Environmentalists in Virginia appear divided over his record as the state's legal officer; two held a news conference to say he did not do enough to enforce environmental laws, while others say he has a record he can be proud of.

As a legislator, Baliles did not attract attention with any major bills, although he impressed many colleagues with his thoughtfulness and contributions in committee. His main success was in sponsoring bills to require businesses to report to the state on their use of hazardous materials, to establish a Virginia Film Office and to set up a liaison office for the state with the federal government as well as the right turn on red bill.

But Baliles' critics say that during his six years in the House of Delegates he at times showed a lack of courage on controversial issues.

They cite his 1979 vote to refer a resolution to adopt the Equal Rights Amendment to a committee even though its sponsor rightly predicted it would die there. They also note that he missed a crucial House vote on a controversial bill in 1981 to provide state funding for abortions in cases of rape, incest and fetal abormalities.

"My impression is he doesn't always take a leading role on the great issues of the day," said Del. Warren G. Stambaugh (D-Arlington), who supports Davis, Baliles' opponent.

Baliles described the ERA vote as "procedural and not a vote on the substance or the merits" and said some other ERA supporters voted with him.

He said he was not purposefully absent during the abortion vote, although he does not recall why he missed it. He said the strong public stand he has taken in favor of abortion rights shows he would not try to duck the issue. Two weeks ago, alone among the gubernatorial contenders, Baliles came out against a controversial move to restrict abortions for minors.

Baliles discounted fears that he is too cautious to make any dramatic moves if elected governor, saying that as a relatively junior legislator and as attorney general, "there is only a limited opportunity to offer proposals of a visionary nature.

"This is really the first time in a relatively short political career that the opportunity is there to . . . exert the boldness and vision that I think are required for the future," he said. "I will have a number of initiatives and some will be bold and innovative."

As soon as he begins talking of his plans for the state, Baliles slips quickly into his serious mode. It's a side of him Jeannie Baliles has known for a long time.

At Wesleyan, she went along with him when he visited a fellow student and his father, a prominent labor leader, to work on setting up a seminar on how to bringing together labor and business. It was their first date.