Following a closed, all-night session full of insults and accusations, the sixth nonaligned summit meeting ended quietly here this morning with Cuban President Fidel Castro proclaiming the movement "more unified, more powerful and more independent than ever."

Despite predictions by some that the summit would "explode" because of "serious obstacles" and divisions, Castro said, "we have overcome the difficulties, approached the hardest problems and reached agreements on every single issue."

A last-minute argument over condemnation of Egypt, which turned into an exchange of hostility over the "serious obstacles" Castro referred to, brought the movement closer to a flash point than perhaps at any other time during its six days. It extended the planned 8 p.m. closing ceremony last night into a 14-hour session that left some delegates asleep in their chairs when the end came this morning.

The session was to discuss a joint Arab-African proposal calling for denunication of the Camp David accords and of Egypt for "betraying" the Palestinian people by its peace treaty with Israel.

Rather than suspend Egypt's membership in the organization as some of the more militant Arab states had urged, the proposal, which was eventually adopted, called for an 18-month probation during which Egypt's foreign policy, particularly its relations with Israel, would be studied by a committee.

Liberia, Malawi, Togo and Senegal objected that the proposal did not reflect the views of all African states.

According to a number of delegates present at the closed session, the head of the Senegalese delegation then charged that the decision on what to do with Egypt was probably made in Cuba, as part of a militant cabal, before the summit even started.

Many nations present, he reportedly said, were acting like Cuban "puppets." With the Middle East 20,000 miles away from Cuba, he said by way of exaggeration, it was easy for Cubans to be revolutionary there, The Senegalese said he realized he probably would be punished for his outburst by an orchestrated chorus of Cuban defenders.

He was. Benin's delegate launched a flurry of ins,lts and Mozambican President Samora Machel, according to several delegates, said the Senegalese must be "under the influence of drugs or drink."

The Cuban delegation reportedly called the delegate from Senegal a "rat." Cuban Vice President Carlos Rafael Rodriguez said that Cubans do more than just talk about revolution and that if such a statement had been made outside a diplomatic forum, revenge would be demanded for Senegal's lack of respect.

The battle and the night wore on. Egyptian Foreign Minister Boutros Ghali reportedly spoke three times in defense of his country's peace program, scheduled a predawn press conference and then canceled it.

Just after sun-up, the delegates emerged red-eyed and haggard.

Under their arms they carried a final overall declaration weaker than host and main author Cuba originally had proposed, and too strong for the taste of some. The declaration will be the bible of the nonaligned movement until the next summit three years from now. Despite the differences, it seems to have left all more or less satisfied, or at least more exhausted than combative.

After days of arguments and amendments, a group of moderates led by Yugoslavia succeeded in taking out much of what they saw as Marxist jargon and substituting generalized phrasing they considered more in keeping with the movement's founding principles.

Thus, talk of "the yolk of oppression" was deleted. Some references to the West were broadened to include the Soviet bloc in a general denunciation of big-power imperialism and expansionism.

But the United States was singled out several times for strong criticism.

"Far from working for peace," in the Middle East, the document says, "the United States is trying instead to obtain partial solutions that are favorable to Zionist aims and underwrite the gains of Israeli aggression at the expense of the Palestinian Arab people and the entire Arab nation. For this reason the conference condemns American policies and maneuvers in the region."

The United States was "denounced" for supplying arms to Israel and "condemned" for trying to "increase and consolidate [its] military presence in the region, [and for] threats . . . to use force against the Arab countries, in particular the oil-producing countries."

Castro, whom the Yugoslavs and others fear will shift the movement toward the Soviets during his three-year chairmanship, promised that Cuba "will never use the movement to benefit our country, but shall use it to struggle and to work for others."

For now, Castro said, it is not for Cuba "to say the sixth summit has been a success. That shall be a task left for history."

Castro then strode off the podium to embrace the leaders that many here felt represent the old and new currents of the movement -- Yugoslavia's Marshal Tito and Vietnam's Pham Van Dong.