The giant United Brands Co. fruit conglomerate, losing money on Costa Rica's west coast, is shutting down its massive banana operation there despite protests from Costa Rica's government and much hand-wringing by the Reagan administration.

Costa Rica, long hailed as a showcase for democracy in Central America, fears that shutting the plantations could lead to leftist-inspired riots over the sudden unemployment and to economic disintegration from the loss of income. The State Department has the same worries and has been sitting in on talks between the company and Costa Rica.

But the administration, torn between its firm support for the tiny democratic nation and its equally firm support for free enterprise, has not taken sides.

United Brands has grown and harvested bananas on four town-sized plantations on Costa Rica's west coast since 1938, when it was still United Fruit and reputed to have a finger in every Central American political pie. Latins have long called the company "the octopus" and accused it of buying and selling politicians as easily as it did bananas.

United Brands' operations on Costa Rica's Atlantic coast, which are not affected by this dispute, date to 1898 but involve purchasing and selling independently grown fruit.

An estimated 50,000 Costa Ricans depend directly or indirectly for their living on the Pacific coast plantations, which include schools, housing, a railroad, a port and ships.

Costa Rica relies on the bananas for about $40 million a year in concessionary payments and taxes on exports and workers' incomes, a crucial sum in the context of the nation's $4 billion foreign debt.

But two people were killed and many others injured during a 72-day wage strike at the Pacific sites by leftist banana workers' unions last year. United Brands decided to shut down the operation last October because its production, already damaged by the strike, no longer could compete in the U.S. west coast market with cheaper fruit from Ecuador and elsewhere.

"We recognize the severity" of the decision's impact, "but we can't afford to continue something like this," said George M. Skelly, United Brands' senior vice president and general counsel, reached at the company's New York headquarters. He said the firm will continue its Atlantic coast activities and will continue paying 1,000 nonworking west coast employes at Costa Rica's request, in hopes that Costa Rica can take over the Pacific operation.

Danilo Jimenez, minister of the presidency of Costa Rica, said in a recent interview with Washington Post foreign editor Karen DeYoung that "the social and economic consequences of this are enormous." He said an International Monetary Fund agreement to help Costa Rica with its debt problems hinges on stable banana production and that United Brands has four years to run on its 50-year banana-planting contract.

"I trusted that the American government would be more interested in helping our little democracy to strengthen itself than in helping a company that may be, apparently, in breach of contract," Jimenez said. He and the Costa Rican foreign minister met in Washington last month with State Department officials and with United Brands officers.

But the State Department has remained neutral in the dispute. The Reagan administration regularly hails Costa Rica as a shining example of a functioning democracy and a bulwark against the leftist Sandinista government of neighboring Nicaragua, but "we can't get involved in the commercial operations of a U.S. business overseas," as one State Department official put it.

"The U.S. government is never going to lean on a U.S. business that feels it has to do something like that for purely commercial reasons," he said.

This policy has frustrated other nations as well. The Dominican Republic, also a functioning democracy, tried last year to win special consideration for its sugar -- practically its only export -- in U.S. markets but was blocked by U.S. sugar interests. It has threatened to default on its international debt as a result.

Puerto Rico also faces massive unemployment despite its special commonwealth status, but its diplomats routinely complain that they cannot get a hearing when Congress is considering crucial tax and welfare legislation.

The situation has led some critics to charge that Washington pays no attention to friendly nations unless they are facing a communist threat and that U.S. aid rarely helps in solving structural economic problems.

The State Department official disputed this. He said U.S. aid to Costa Rica totaled $212 million in fiscal 1984 and will be at least $220 million this fiscal year, about 5 percent of the Costa Rican gross national product and more per person than the United States gives any other country except Israel.

"What will make us happy is some agreement that keeps some of those plantations operating so that United Brands stays there and Costa Rica feels good about it," he said.

Skelly said the company's west coast banana plantations were losing $6 million a year because of low world banana prices before the strike, which shut down operations. During the strike, more than a third of the banana plants were lost to a fungus for want of spraying, and the rest deteriorated, he said, for a further loss estimated in September at $6 million.

"It's much more now" because the fruit is being left to rot, Skelly said. "Basically, we've never gone back."

The company and the country began negotiating on tax rates and fruit prices in mid-1983 in an effort to avoid the current impasse. Skelly denied that the company had abrogated its contract, asserting that it requires only that bananas be planted, not that they be harvested and sold.

In December, United Brands proposed a package under which it would sell its 3,000 employes on Costa Rica's west coast their homes and land parcels for token prices and sell the rest of its Pacific operations to the Costa Rican banana authority for $15 million. "We'd love that, but we haven't got $15 million," a Costa Rican embassy official said.

Current talks concern some kind of lease-back arrangement in which Costa Rica would buy the property over many years, rehabilitate the half of it that can be saved and sell the bananas it produces to United Brands at a reduced price.

In theory, Costa Rica could expropriate the property or sue United Brands for breach of contract, but neither is likely. "We don't want to alienate other possible investors," the embassy official said.

Skelly is optimistic that some way will be found to keep the plantations running but is firm that United Brands is leaving. "I can't see any outcome in which we continue shipping bananas out of the west coast," he said. "That's final."