A federal appeals court, ending a bitter four-year struggle between the Teamsters union and area liquor wholesalers, yesterday ruled that the Teamsters were illegally replaced by nonunion employees and should be reinstated with back pay and benefits.

The U.S. Court of Appeals ruled that the Association of D.C. Liquor Wholesalers, which represents Forman Brothers, Washington Wholesale Liquor Co. and Beitzell and Co. in labor relations, had illegally declared a negotiating impasse in early 1987 when it locked out the 120 members of Teamster Local 639 and hired replacement drivers and warehouse workers.

The three-member appeals court panel upheld a ruling by the National Labor Relations Board that all locked-out employees be rehired with full back pay, less any interim earnings they may have had, and full health and retirement benefits.

Attorneys for the union estimated the cost to the companies at about $10 million.

Milton S. Kronheim & Co., the district's other major liquor wholesaler, is not a member of the association and was not involved in the dispute. Teamster employees at Kronheim have been without a contract, however, pending the outcome of the legal action against the other companies.

Phil Feaster, president of Local 639, called the court decision a "great victory. The whole labor community has been watching this case." He said he hoped the decision would "send a message" to management that it can't act illegally at the bargaining table in an effort to bring in cheaper replacement workers.

But Feaster said in many ways it was only a moral victory for many of his members at the three companies. "Some of these workers' lives will never be put back together," he said. During the four years, Feaster said, some members lost their homes or faced other setbacks as a result of the economic losses they suffered.

At the time of the 1987 lockout, Teamsters at the three association companies earned slightly more than $12 an hour, according to the union. When the association companies cut their wages, Kronheim told the union it could no longer afford the $12-an-hour rate, but the union refused to sign a new contract at anything less than the existing rate. Replacement workers were paid $8 an hour.

Joseph Gallagher, president of Washington Wholesale Liquor Co., and Ronald Tisch, the association's chief labor negotiator, did not respond to telephone calls yesterday.

Teamster attorney Hugh Beines said one of the companies -- Beitzell -- is in the process of liquidating its assets under voluntary bankruptcy, and Washington Wholesale Liquor was purchased several years ago by a New York company. But the terms of that purchase agreement require the buyer to assume all debt obligations.

In upholding the National Labor Relations Board and a subsequent lower court decision, the appeals court yesterday said it found no reason to dispute the findings that the companies had refused to bargain in good faith and that their declaration of an impasse was illegal.

The court noted that the association negotiated on wages for only one day before declaring an impasse when the union refused to accept wage concessions. The two sides negotiated a total of just 12 days, the court noted.