Cuba's loss of a hard-fought bid for a Security Council seat has dealt a heavy blow to Fidel Castro's hopes of leading the Third World.

In the view of some observers, the Cuban withdrawal Monday from a contest over a vacant chair on the 15-member council, coupled with Third World shock about the Soviet invasion of Afghanistan, also has given the United States a unique opportunity to better its relations with developing nations.

But representatives of the 95-member nonaligned movement have warned against a U.S. push to befriend them at the public expense of the Soviets.

They caution that the issue of Cuba, along with current events in Afghanistan and Iran, marks a turning point for their loose organization, which must be left to find its own direction.

The challenges it now faces have added importance because a shifting U.N. balance over the past decade has given the nonaligned movement, on issues where its members are united, an international voting majority over both the Eastern and Western blocs.

An indication of the impact of recent events on the movement is that Cuba's ultimate loss in the council race was engineered by such leading nonaligned members as Nigeria and India, who earlier had been influential backers of Havana.

How this happened, and how the nonaligned nations feel about the Iranian and Afghan questions now before the United Nations, go to the heart of the 20-year-old movement founded by Egypt's Gamal Nasser, India's Jawaharlal Nehru, Yugoslavia's Tito and Indonesia's Sukarno.

Although the basis of their coalition was to form a neutral hedge against the big powers, nonaligned policy, in the view of the West, has shifted toward the Soviet bloc, or at least sharply to the left, in recent years.

"We are used to having the Soviet Union on our side," acknowledged a Yugoslav diplomat, whose government has criticized the Soviets' Afghan move. "The Soviets were, and are, helping liberation movements" in other countries.

Yet, the Soviet invasion of Afghanistan, a nonaligned charter member, "is not easy for some members to accept," he said. "We are facing a new dimension of Soviet policy."

Now, an Asian ambassador said, "we have to rethink our basic concepts, that imperialism is fundamentally synonymous with the West."

Most of the Soviet Union's strongest Third World allies, including Cuba and Ethiopia, have declined to criticize the Afghan invasion. But according to one informed diplomat, what is more important is that they have not praised it.

"What is important is that no non-aligned member rose in the Security Council to defend the Soviet Union except Vietnam and Laos," the Yugoslav said.

Other influential nonaligned countries with strong ties to Cuba, such as Jamaica, have made what their colleagues call "courageous" statements calling for the withdrawal of Soviet troops. The Soviet-vetoed Security Council resolution "deploring" the invasion was sponsored by six nonaligned council members.

The Afghan issue, Norway's delegate said last night, "is not primarily a NATO affair or an East-West issue. It is a problem between the nonaligned nations and the Soviet Union.A nonaligned country is being overrun."

Iran presents the movement with a more complicated problem. "The Iranian revolution and the overthrow of the dictator shah has all our sympathies," said the Yugoslav diplomat. But "the occupation and hostages . . . are not justified under any circumstances."

According to an influential African diplomat, "the nonaligned movement is very strong on international law, because we have no other arms to defend ourselves. When one of us decides to violate those legal concepts, we cannot approve."

The Third World is still divided over economic sanctions against Iran. Movement members overwhelmingly favor an initial U.N. resolution late last year calling on the Iranians to release the American hostages. Nigerian Ambassador Akporode Clark said, "Many of us felt it would give them a way out to release the hostages" without directly bending to the United States.

Now the United States has decided to press both the Afghan issue in the United Nations General Assembly as well as the question of sanctions against Iran in the Security Council. The Third World countries are about to be called upon to risk public exposure of long-standing divisions they rarely have had to air.

"There have always been three streams in the movement." Clark said: "the Cubans along with Algeria and others;" the kingdoms and rightist Middle East states that side with the United States; "and the mainstream which is left of center and forms the bulk of the membership. It is led by countries like Yugoslavia and India."

Many members acknowledge that it was with Cuba's bid for the movement's leadership that the splits deepened.

As current chairman, Cuba hosted the most recent nonaligned summit last September in Havana. Many members joined Tito in criticizing Castro's alliance with the Soviet Union. But the majority was willing to go along with Cuba's militancy for its own reasons.

The majority of the Arabs benefitted from Cuba's pro-Palestinian activitism. For the Africans, Cuba's leadership meant harsh denunciations of southern Africa's white minority governments. While many Latin American nations objected to Cuba's pro-Soviet leadership, a few -- such as the new governments of Grenada and Nicaragua -- saw support of Cuba as a way to break their traditional dependence on the United States.

But in the view of many members, Cuba went too far in its heavy-handed direction of the summit and its efforts to push its own views on such issues as Cambodia.Castro, like the Soviets, has insisted on support for the new Vietnamese-installed government, which others find as odious as the previous Pol Pot government.

Still, the nonaligned majority supported Cuba's Security Council bid when the U.N. General Assembly first voted on it in late October.

Again, the Asian said, "the Arabs with one or two exceptions voted for Cuba on the very simple thesis that, on Mideast questions, Cuba is more reliable" than Colombia, its competition for the chair.

But a minority, with the bitter recollection of the Havana meeting, lined up with the United States and its allies to prevent Cuba from obtaining the required two-thirds majority in the General Assembly. The voting continued through an unprecedented 156 ballots.

"Those voting for Colobia were essentially voting against Cuba," Nigerian ambassador Clark said. "They were a solid bloc, I had instructions to support Cuba, because it would have reflected our view on southern African issues like Namibia sanctions.

"But it was quite clear that Cuba could not get more votes. The thing was getting out of hand, and becoming a waste of everyone's time."

Cuba rejected the suggestion of nonaligned friends that it and Colombia each take the seat for a single year.

After the 150th ballot last week, Nigeria and other pro-Cuba members decided to take action. If Cuba would not share the seat or withdraw, the tricontinental caucus of African, Asian and Latin American delegations would vote a resolution ordering it to do so.

"I went to [Cuban Foreign Minister Isidoro] Malmierca last Friday, and told him very clearly," Clark said. "There is a tradition here that even committed votes can withdraw after the second or third ballot." Malmierca whose presence in New York refelcted the importance Cuba placed on the issue, "didn't agree," Clark said.

"But while we were sitting there, a call came saying that there had been another ballot and, for the first time, Columbia had won a one-vote majority." a

The reason was the invasion of Afghanistan, a nonaligned member, by the Soviet Union, a Cuban ally. "Many of us were very shocked," Clark said.

The Soviets "didn't even consult Cuba on the invasion, Clark said. "These are the problems of thinking your are an ally of a great power. You're being used."

Last weekend, a compromise was arranged within the movement. Clarfk and others shifted some face-saving votes back to Cuba, and with a simple majority but still lacking the necessary two-thirds, Cuba withdrew. By the terms of the compromise, Mexico was nominated and quickly elected.

Clark and other influential nonaligned delegates maintain the exercise has strengthened the movement. Just as it worked out the Duba dilemma, they say, the movement will find its way through the quandaries of Afghanistan and Iran.

"I think that after Havana," Clark said, "the nonaligned is undergoing tremendous strain. But in the end, certain things become clear. There are no natural allies."