District of Columbia officials, alarmed by 30,000 tons of sludge compost that have piled up at the city's Blue Plains sewage treatment plant, said yesterday they may cancel a five-year, $77-million contract with the firm responsible for removing the sludge.

Dano Resource Recovery Inc., a Virginia firm that twice before won and then lost contracts with the city to treat and haul away part of the sludge generated at the Southwest Washington plant, may lose a third contract because of its inability to sell or dump the mountains of sludge that it treats at the plant site.

William Johnson, director of the D.C. Department of Environmental Services, which operates Blue Plains, said he notified Dano on April 11 of "a number of deficiencies" in its operations, including the massive sludge buildup. The firm missed a deadline for explaining how it intended to remedy those problems, according to Johnson.

Asked yesterday whether the city intends to terminate the contract with Dano, Johnson replied: "Let's say that it's a notion at the moment."

Thomas Downs, director of public works and transportation, said the city is fast running out of space at Blue Plains to store the treated sludge. He said the city may have to either assume responsibility for disposing of the sludge compost or find another firm that can.

"If it the buildup continues, we'll be very concerned . . . because without the space, at some point you begin to jeopardize the other operations at the treatment plant," Downs said.

Henry Valentino, a vice president of Dano, acknowledged that his firm was having trouble disposing of the sludge, but said that Dano is "close to resolution of this problem."

"The problem is not our fault," Valentino said. "There are a number of contributing factors . . . beyond our control."

Under the latest contract, which was signed last year, Dano agreed to build special treatment equipment that, when fully operational, will convert 900 tons of sludge each day to fertilizer that can be marketed. Dano, whose facility currently operates at less than 20 percent of capacity, hasn't been able to produce a sludge compost that can be marketed.

Valentino said there's nothing wrong with the equipment used by his firm to treat the sludge, but that an unusually heavy rainfall in recent weeks and poor drainage at the site have left the compost saturated and unfit for sale.

"We need to move it temporarily . . . to dry it and to screen it," Valentino said. "Once it's been screened, it will be suitable for marketing."

The city's problems in dealing with Dano date back to 1979, when Mayor Marion Barry's administration signed the first of three contracts with the firm to deal with the sludge produced at Blue Plains, which currently totals 1,080 tons each day.

The city originally signed a $20 million sludge removal contract with the firm in 1979, but Dano did not live up to the agreement and never was paid. Barry signed a second, $39-million contract with Dano in 1980 to treat the sludge on site and then remove it, but that contract was canceled in May 1981 because of insufficient financing.

Barry gave the firm a third chance to complete the project in July 1981, after developer Theodore R. Hagans Jr., a politically influential friend of the mayor, emerged as a managing partner of the firm.

However, officials of Dano and Hagans had a falling out and Hagans never actually got involved in the project. Instead, Dano formed a joint venture with a subsidiary of Williams Industries Inc., Atlas Machine and Iron Works Inc., and several other firms to handle the city contract.

The District so far has spent $1.3 million on the current contract. Dano potentially could receive a total of $77 million over the life of the five-year contract.