Two years ago, the overthrow of Nicaraguan dictator Anastasio Somoza by the Sandinista rebels seemed to be no more than a revolutionary pipe dream. My reporter Bob Sherman, send to find out who the Sandinistas and their supporters were, reached them through Costa Rica, which had offered refuge to the rebels. The Sandinistas had trained their fledgling army in Costa Rican jungle encampments and were provided sanctuary there after hit-and-run raids across the border into Nicaragua.

Sherman's first contact with the Sandista directorate was in San Jose, the Costa Rican capital. From there he traveled north to the province of Guanacaste, where he visited a rebel camp well within Costa Rican territory. Although the Costa Rican government formally denied knowledge of the Nicaraguan camps, the Sandinistas were operating quite openly in Guanacaste.

The Costa Ricans' not-so-secret support of the Sandinistas was an act of political courage. Somoza reportedly condemned Costa Rica for its role, and threatened to invade his neighbor. It was no idle threat: Costa Rica has no army, only a civilian police force. Somoza's American-tained, American-equipped National Guard could have crashed through the border with no trouble at all.

Nuisance raids on Nicaraguan army outposts were sometimes launched by rebels who would cross the border in civilian clothes, then pick up arms and uniforms hidden on the Nicaraguan side. After the attack, they would stash their military gear at a safe house and take the bus back to Costa Rica.

The government in San Jose not only turned a blind eye to this provocative, illegal behavior, but also offered refuge to several of the Sandinista leaders in exile. In short, the Nicaraguan revolutionary government owed a heavy debt to Costa Rica.

But such political debts are quickly forgotten. Nicaragua turned on its old ally, Costa Rica, in a scheme engineered by its new ally, Cuba. The stage for this power play was the United Nations.

Last year, Cuba had its eye on the prestigious Latin American seat on the U.N. Security Council, which is lost. So Castro tried again this year, but it soon became clear he wouldn't have enough votes to win the coveted seat.

Cuba chose to deny the Security Council seat it could not gain to an old political foe that had an excellent chance at the seat: Costa Rica. This was accomplished by persuading Nicaragua to enter the competition for the post at a time when Costa Rica was within a few votes of victory.

Costa Rica's U.N. ambassador, Rodolfo Piza Escalante, told my assoicate Lucette Langnado that his countrymen were so indignant at Nicaragua's backstabbing that relations between the two countries may be seriously damaged.

What was most disillusioning to the Costa Ricans, the ambassador said, was that the Sandinista government clearly demonstrated its willingness to be Castro's puppet -- just as Castro is regarded as the Kremlin's puppet.

"We told them flatly they were being used," the ambassador said, referring to high-level exhcanges with the Nicaraguans. The warnings were ignored.

Costa Rica, realizing it couldn't win the council seat, withdrew, and the position went to Panama. But much bitterness remains.

Though technically the leader of the "non-aligned movement," Castro's Cuba had lost face with many Third World governments by its slavish support of the Soviets' invasion of Afghanistan. And the non-aligned countries have begun reassessing their views of Cuba in the light of its role in the Security Council controversy. Cuban support for the Vietnamese and their puppet regime in Cambodia has also helped to diminish Castro's influence in the Third World.

"There is a definite erosion of Cuban power at the United Nations," confided one U.N. diplomat.

Another high-level diplomat observed that "for a country that is 'non-aligned,' Cuba is pretty well-aligned.

In fact, Cuba's role as the spoiler in the U.N. Security Council fight may presage a growing and irreversible disenchantment with Castro among Third World nations.

Footnote: A spokesman for the Nicaraguan U.N. delegation insisted that Cuba had played no role in his government's decision to compete for the Securtity Council seat against Costa Rica. The spokesman added that Nicaragua would "continue to support Costa Rica and to enjoy good relations with it."