OSHAKATI, Namibia (AP) _ A crowd of more than 5,000, mostly schoolchildren, chanted and sang political songs as they marched six miles behind a U.N. convoy carrying released SWAPO guerrillas toward the border Thursday.

The crowd began gathering at dawn at Ongwediva Lutheran mission station, where 31 guerillas spent the night after greeting streams of Namibian peasants who came to see them and participate in a church service.

Most black schools in the area around the garrison town of Oshakati were closed Thursday as the students marched.

U.N. police monitors watched the procession, which grew larger as it progressed. South-West African police were barely visible, and army patrols were non-existent. The South African-controlled military was restricted to base from Wednesday to Saturday to allow the estimated 600 guerrillas in the territory a safe route to the border.

The South-West African People's Organization guerrillas endangered a U.N. independence plan for Namibia when they crossed the border from Angola on April 1. Under the plan, they were to wait in their Angolan bases until mid- May when they were to return, unarmed, as refugees to take part in November elections.

South African-controlled military forces, which had been confined to base in accordance with the plan, were released to fight the SWAPO incursion. According to Namibia Administrator-General Louis Pienaar, the battles caused the deaths of 305 infiltrators and 27 security force members.

The United Nations said Thursday at Windhoek, the territorial capital, that 3,941 military personnel from 21 countries are deployed in Namibia to help monitor the transition to independence.

The South African military on Wednesday turned over to the United Nations 31 guerrillas captured in the fighting.

At midday Thursday, 28 of them walked across the border at Ruacana and got into trucks to carry them to their bases 100 miles to the north, a territorial official said. Three injured fighters were taken elsewhere to recuperate.

The United Nations is supervising a transition period and elections aimed at ending South Africa's 74-year rule over Namibia.

The independence plan is tied to a southern Africa peace agreement that provides for withdrawal of South African and Cuban forces from Angola.

American, Soviet, Angolan, Cuban and South African delegations met Thursday in Cape Town, South Africa, to discuss developments.

''This is perhaps the most serious meeting the joint commission has faced so far,'' South African Foreign Minister Pik Botha said in welcoming the delegates. '' Since we last met ... in Namibia we tried our best, all of us, to deal with the serious problem that has arisen as a result of SWPAO's incursion and violations.''

The meeting represents the first time in decades that Soviets, Angolans and Cubans have made an official visit to South Africa, since relations were broken over the country's laws of apartheid - racial separation.

Bishop Cleopas Dumeni, the head of the Evangelical Lutheran Church in Namibia who conducted church services at the Ongwediva mission Wednesday evening and Thursday morning, suffered the loss of a son killed by security forces and a daughter killed by a bomb explosion blamed on SWAPO during the 23-year bush war.

He told the SWAPO fighters, ''They (the villagers) have come to see you and admire you. The coming of the group here shows that they appreciate your great sacrifice.''

Some of the guerrillas greeted family members they had not seen for five to 13 years.