Virginia Attorney General Gerald L. Baliles said today he will resign June 30 in an attempt to keep his office free of politics during his campaign as the Democratic nominee for governor.

"I do not wish to see the actions of the attorney general's office challenged or scrutinized for political motives during the remaining six months of the term," Baliles told reporters at a news conference with Gov. Charles S. Robb.

Robb said William G. Broaddus, 42, Baliles' chief deputy, will serve until mid-January when the winner of the race between Democatic Del. Mary Sue Terry of Patrick County and Republican Del. W.R. (Buster) O'Brien of Virginia Beach assumes the office.

Four years ago, Democrats attacked Baliles' predecessor, Republican J. Marshall Coleman, for refusing to give up his office during his campaign for governor, saying he was violating an honored tradition by remaining in that office while seeking another position.

Baliles, 44, had announced earlier this year that he would resign the $56,000-a-year position if he won the right to oppose Republican Wyatt B. Durrette in the fall elections.

"It is my belief that the demands of the campaign will require my full time and attention," Baliles said. Robb said has been discussing the likely vacancy for the past three months.

Broaddus, a longtime associate of Baliles, has served as chief deputy attorney general for three years. He served in the office under a previous Democratic administration and then worked as the county attorney for Henrico County, a Richmond suburb.

A Richmond native and graduate of Washington and Lee University and the University of Virginia Law School, he served as a law clerk to Justice Harry L. Carrico of the Virginia Supreme Court.

"I look foward to continuing the remarkable commitment and march toward excellence of Jerry Baliles," he said.Baliles, who upset Durrette in the 1981 elections, oversaw a reorganization of the office that includes 125 lawyers, and an annual budget of about $8 million. It has limited authority in criminal cases, but serves as adviser to almost all state agencies and the governor.

Until 1982, Baliles' first year in the office, many assistant attorneys general were spread throughout the state government, with only a small number working directly with the attorney general. The consolidation plan, spurred by a legislative report, placed all the attorneys under one office in downtown Richmond.

"It was the first time the attorney general was aware of the state's total legal budget and had control of it," said David Hathcock, Baliles' spokesman.

Baliles, a former assistant attorney general and Richmond area delegate to the General Assembly, fulfilled his campaign pledges by establishing two special units, one to investigate Medicaid fraud and abuse by health-care providers and the other to pursue overdue debts and court claims owed state agencies.

Hathcock said the offices during 1983-84 were responsible for collecting about $30 million in fees and fines during a time the total budget of the attorney general's office was about $7.5 million a year