The Virginia House of Delegates, bowing to an intensive lobbying campaign by local government officials narrowly killed a bill today that would have empowered the State Corporation Commission to set the rates state and local governments must pay for electricity.

By a 46-44 vote, the House rejected the bill, which opponents charged would cost the governments millions of dollars each year and end the practice of allowing the governments to negotiate over the rates they pay.

The bill's sponsor, Del. Frank M. Slayton (D-Halifax), blamed the defeat on weekend lobbying by local governments, which he said centered on a "person attack" on him. Slayton said he was criticized because his South Boston, Va., law firm represents Virginia Electric and Power Co., the state's largest electric untility.

In a speech to the House today, Slayton said his ties to Vepco through the law firm had nothing to do with the bill. "Here today I represented a lot of poor consumers who think the time had come to stop subsidizing local governments," he said.

Defeat of the bill was a major setback for the state's electric utilities, the SCC, and some consumer groups that have been fighting for more than four years against the Virginia Municipal League and the Virginia Association of Counties over the issue. In 1972 the State Supreme Court set the stage for the debate, ruling that the SCC could not set the local government's rate unless specifically authorized by the legislature.

Slayton argued today that residential and commercial electric customers are forced to subsidize cheap electric rates paid by low governments and warned that the state's courts may be flooded by lawsuits over the issue unless the Assembly acts. But opponents of the bill, led by Del. Thomas W. Moss (D-Norfolk), charged that the bill would create rate increases for the local governments so large that property taxes would have to be raised.

In Fairfax County, officials have estimated that the new procedure could raise the county government's electric bills by $1 million a year. However, the Northern Virginia delegation appeared divided over the issue.

Today's vote was by a show of hands and could have been closer had two Northern Virginians who favor the bill been in their seats when the measure was voted on. Del., James M. Thomson (D-Alexandria) announced he would have voted for the bill and Del. Robert E. Harris (R-Fairfax), who was injured over the weekend had voted for it in committee.

Although the defeat was by only two votes, Slayton said later he doubted that he would attempt to revive the issue and said his sponsorship of the measure did not constitute a conflict of interst as opponents had charged in the weekend lobbying. "If there was any suggestion I was being paid for it, that would be unconscionable," he said.

As it is, he said, his law firm receives a $50-a-month retainer from Vepco to represent the utility in power condemnation proceedings and to help it collect overdue bills. Asked if the power company represents a major of his legal practice, Slayton snapped: "Hell, no."

Slayton did not attempt on the House floor to promise that his bill would bring any reduction in the bills paid by residential customers, only that it might slow in the future the rate of increase in residential electrict bills.

When Moss, the bill's leading opponent, recounted Vepco's support of the bill as a "consumer measure," he was incredulous. "When Vepco comes before us and tells us this is a 'consumer measure' that we support, then I will tell you that the leopard is going to change his spots," he said.

In other action, the House gave overwhelming approval to a revision in the state's juvenile code, but not before attaching a floor amendment that opponents said could result in more juveniles begin jailed instead of being placed in detention homes. The amendment according to Del. Ford C. Quillen (D-Scott), would allow some remote localities without detention homes to place juveniles in jails for up to 18 hours after their arrest.

Generally, the new measure would make it more difficult for state welfare officials to take into custody children who have committed no crimes but who are thought to be in need of foster care or state supervision.

Slayton, who also was a supporter of the juvnile code measure, said local welfare departments are not fulfilling their responsibility to see that such children are promptly placed in foster homes and said the measure would improve accountability for the care of the children. The measure will go to the State Senate after a final House vote Tuesday.

A weakened bill that would have required registration of all automobile repair facilities in the state and provided for optional certification of mechanics was withdrawn from the Senate floor and returned to committee when its sponsors said they feared the measure would likely be defeated. Sen. Adelard L. Brault (D-Fairfax) said he would consider some form of legislation that would authorize localities to enact such measures on their own.