The D.C. City Council yesterday granted Mayor Marion Barry's request and voted unanimously to repeal his short-lived and highly controversial 6 percent tax on gasoline sales in the District of Columbia.

But in acting promptly to eliminate a levy that officials say was not only politically unpopular but a nightmare to collect, the council threw the city's budget out of balance by as much as $9 million, and some members feared the imbalance would carry over into future years.

The tax, enacted in August, added about eight cents to the cost of a gallon of gasoline in the city and drove thousands of motorists to suburban Maryland. It was the strong feeling of most council members yesterday that the tax was an idea whose time should never have come. And in the wisdom of hindsight, Barry agreed.

"I started thinking about an adjustment about three weeks after it [the tax] took effect," Barry said, minutes after the council voted to repeal the tax effective Monday. Barry then walked over to Vic Rasheed, leader of a group of service station owners who had bitterly protested the tax, and said, "Sorry it took so long."

Rasheed, president of the Greater Washington-Maryland Service Station Association, said he met with Barry three weeks after the tax took effect and showed him figures indicating that gasoline sales in the District had plummeted since the levy was imposed.

"He told me that if these were the figures, then he would take steps to make sure that changes would be made," Rasheed said. "I really expected him to take action about two months ago."

The gasoline tax was a key part of a program of tax increases Barry proposed last summer to help alleviate the city's budget crisis. The District's total deficit now stands at $409 million, according to city figures.

In a letter to the council Monday asking for repeal of the tax, Barry proposed instead increasing the long-standing 10-percent-per-gallon excise tax on gas to 11 cents, and making up the rest of the lost revenue -- around $9 million -- by taking advantage of a recently enacted law authorizing the city to seize bank accounts in the District that have been inactive for seven years or more.

Barry said the city could obtain at least $15 million a year in both 1981 and 1982 by using the new provision. But the law is not expected to pass the required 30-day congressional review period until March at the earliest. In addition, testimony before the council last month indicated that it was uncertain how much money is available in the inactive accounts and how long it will be before the city can collect any of the funds.

Some council members said yesterday that the decision to seek the funds from inactive bank accounts was little more than a convenient device for Barry to make up the lost revenue on paper at minimal political cost.

"I think we're starting the two-year giveaway," said John A. Wilson (D-Ward 2), chairman of the council's finance and revenue committee. "Every time, about two years before the [mayoral] elections, we give all this tax relief and then we're in trouble when it's over."

Wilson was referring to the period before the 1978 mayor's race when then-mayor Walter E. Washington and Barry, as council finance committee chairman, engaged in a vigorous battle of oneupmanship to see who could lower property tax rates the most.

"Before this year is out, somebody might introduce a bill to lower the current rates or freeze the [property] assessments," Wilson said. "You start these gimmicks, and then you're in trouble. Probably the gas tax wasn't working. Business wanted it changed, the citizens wanted it changed, everybody wanted it changed, so I guess we had to change it. But maybe we didn't give it enough of a chance."

Barry has told some associates that he plans to seek reelection in 1982. Among the possible challengers, some say, is Wilson.

Barry contended yesterday that the decision to seek to replace the gas tax revenues with the seized bank accounts is a politically neutral action that "doesn't hurt anybody." But he said his decision to ask repeal of the levy was not politically motivated, insisting instead that he had simply concluded that the tax did not work.

Figures compiled by the city's Department of Finance and Revenue showed that District gasoline stations ordered 30 percent less gasoline over the last three months than they did during the same period last year. The states of Maryland and Virginia also showed declines, but far smaller ones. Barry said the drop in sales was causing stations not only to lose profits but to lay off workers as well.

In addition, city officials acknowledged yesterday for the first time that the tax was extremely difficult to collect. "These small stations aren't set up to handle this sort of thing," Barry said. "We might even make more money in the long run through better collections."

J. Walter Lund, head of the tax administration branch of the city's finance department, explained that "one of the problems we had was getting the monthly payments made on time. Many of the small stations found themselves caught in a cash flow problem, and they filed the tax later than they should have."

Rasheed said the dealers "spent the money trying to buy gas or pay their help. In many cases, the dealer just didn't have the money to pay the tax."

Neither Lund nor Rasheed could provide precise figures on how many of the dealers were having problems paying the tax or how much money the city had failed to collect.

Still unresolved is what tax Barry plans to increase to replace the gas tax revenues after the lion's share of the inactive bank accounts have been impounded in 1981 and 1982. Thereafter, the bank accounts will provide less than a million dollars of revenue annually, the city estimates.