A dispute over a $29.64 tax bill ended yesterday with a U.S. Tax Court ruling that the Internal Revenue Service must refund millions of dollars to 2.1 million shareholders of American Telephone & Telegraph Co.

The court said the IRS erred in holding the shareholders liable for federal income taxes on stock distributed to them as part of the 1984 breakup of AT&T.

The ruling is final, because both sides in the case agreed in advance to abide by the court's decision. An IRS spokesman said yesterday that his agency will start working on a plan to distribute the refunds.

"This dispute with the IRS is resolved," said M. Carr Ferguson, an attorney in the Washington office of Davis, Polk and Wardwell, which represented the Edna Louise Dunn Trust, the plaintiff in the matter.

Ferguson said that the case also might serve as a precedent for the disposition of legal challenges involving the tax liability of stock distributed as part of corporate breakups.

The Dunn Trust, administered by Morgan Guaranty Trust Co. of New York, filed a complaint against the IRS alleging that the trust wrongfully was accused of underpaying its 1984 federal taxes by $29.64.

The supposed tax underpayment was related to proceeds the trust received from its share of the AT&T stock distribution.

The trust, which owned 400 shares of AT&T stock, had received 40 shares of each of the telephone giant's seven regional holding companies that were created as a result of the 1984 breakup.

Dunn Trust lawyers argued that, under the Internal Revenue Code of 1954, no gain or loss would result from the transfer of stock involved in the AT&T divestiture.

The IRS agreed that there would be no taxable income from the stock in six of the seven regional companies. But the agency ruled that 39 cents of each share of stock in the seventh holding company, Pacific Telesis Group, would be taxable.

The IRS singled out the PacTel stock distribution because the company had received taxable assets from Pacific Telephone & Telegraph, another property held by AT&T before the breakup. The implication was that, by spinning off the PacTel stock, AT&T was trying to reduce its own earnings, profits and accompanying tax load.

But Tax Court Senior Judge Theodore Tannenwald said that the IRS chose the wrong route for pursuing that argument.

If the IRS "feels that a transaction of the type involved herein represents an obvious attempt to bail out earnings and profits in violation of the purpose of the IRS Code , he is not without his remedy: He can challenge such a transaction as a 'device' . . . He has chosen not to do so in this case," the judge said.

The IRS' case against the trust and, by extension, against all members in that class was based on an "overly broad construction" of the law, Tannenwald said.