The Reagan administration's hopes for a major diplomatic success in a Marxist-led African nation that does not even have relations with the United States are mired in this war-shattered, deserted village, about 25 miles short of success.

That is the distance from Ngiva to the frontier Angola shares with the disputed, South African-controlled territory of Namibia. Stationed in the 25-mile deep zone are South African soldiers, part of an invasion force that swept 120 miles north of the border last December. That force has been winkled back toward the border by American diplomatic efforts but refuses to stage a final withdrawal.

Here at Ngiva, which had 15,000 residents before the invasion but which now counts only a few hundred persons living in the ruins of roofless and collapsed houses, the now familiar fate of a rural farming town caught up in a modern war can be seen in the devastated streets.

But the still incomplete withdrawal has created a byproduct that is as surprising as it is important in the spiral of insurgencies, revolution and border warfare that has plagued southern Africa for more than two decades. Instead of fighting each other, the military establishments of revolutionary Angola and white-ruled South Africa have been cooperating with each other for the past seven months to lower tensions on the ground.

Important differences and antagonisms remain, the most immediate one being the South African failure to meet the March 30 deadline originally agreed to in Lusaka, Zambia, for a complete withdrawal. But there is a budding climate of confidence between the two countries that moderates within each government apparently would like to keep alive.

Moreover, fulfillment of the Lusaka agreement would bring a new measure of credibility to the laborious diplomatic efforts of State Department specialists to arrange a regional settlement in southern Africa. American delivery of a full South African withdrawal and a more moderate Angolan position would help stem attacks on the effort from African radicals and American conservatives who doubt the possibility of reaching a compromise that would suit their separate standards.

Both the lingering tensions and sense of accommodation can be felt on arrival at the small airstrip on the outskirts of Ngiva. As an Angolan Air Force Antonov 26 troop transport bounces to a halt on the bumpy runway, two South African armored cars roll up and troops carrying automatic rifles at the ready jump out to survey the passengers coming off the airplane.

An Angolan officer who welcomes the visitors from Luanda, nearly 1,000 miles to the north, says that troops from the Angolan battalion stationed here do the same when aircraft arrive from South Africa. The arrangement is not covered by the disengagement agreement but has been worked out on the spot.

Six Angolan officers have joined an equal number of officers from South Africa in a formal mixed commission to police the Lusaka agreement. The fact that Angola has agreed to work side by side with representatives of the white-minority government suggests that the Popular Movement for the Liberation of Angola (MPLA) government in Luanda is putting pragmatism over ideology in this experiment.

The agreement requires the Angolan side of the commission to make sure that guerrilla forces belonging to the South-West Africa Peoples Organization (SWAPO) do not use the territory the South Africans have evacuated to infiltrate into Namibia, the disputed territory mandated to South Africa by the League of Nations after World War I under the name South-West Africa.

Angolan officials say that SWAPO has promised to abide by this part of the agreement. These officials add that there have been no problems in enforcing this provision so far, and diplomatic observers confirm this assessment.

"We convinced SWAPO when the agreement was made not to infiltrate from the territory, and that has worked out," said Angolan chief of staff Antonio Franca Ndalu. "And the mixed commission has worked normally,"

"If there is any infiltration now, it is coming from south of the line" jointly patrolled by the Angolans and South Africans "which is under the control of the South Africans. They should complete their withdrawal and let us accept our responsibility for our territory," Ndalu said in Luanda.

South African officials have indicated that concern about guarantees against future infiltration by SWAPO has caused the withdrawal to be halted in its final stages. But by informally calling attention to their preference for a continuing joint patrol along the border when withdrawal is complete, these officials seem to reflect a feeling that the present arrangement is working well.

Ndalu ruled out a formal agreement for continuation of the joint commission after withdrawal. But he said that Angola was prepared to put forward proposals "that would build up confidence in the first month or two after the withdrawal is complete. There would be no need for the joint commission to continue in this form, but there might be something different worked out to patrol the frontier."

The Angolans maintain that South Africa decided to accept the disengagement agreement after meeting heavier resistance in the push north last December and January than they had expected from an expanding and better trained Angolan Army. Foreign analysts credit bad weather with slowing the South African drive and U.S. diplomacy with pushing for a withdrawal agreement as the key to a larger settlement in the region.

Under the agreement, Angola and South Africa each provide a battalion of about 1,000 soldiers to the commission for use in policing the accord. Angola asserts that the South Africans are keeping two battalions of its troops inside the zone south of Ngiva.

Angolan officials who accompanied this correspondent to Ngiva asserted that it was a representative sample of the destruction inflicted on the other villages occupied by South African units in the drive north. They also cited Angola's painful awareness that it faces an enormous task of reconstruction and resettling refugees as a factor in the push to get a lasting detente with South Africa.

There is not a roof left intact in this town. Row after row of modest concrete bungalows gape crazily toward the sky, their asphalt or tin roofs stripped off apparently for the materials. They resemble decapitated and furnitureless doll houses. More substantial homes with roofs of red tile imported from Portugal have been dynamited and holes punched in the tiles.

Angolan officials said there had been no resistance at Ngiva, and inspection of the town indicated that the destruction was more systematic than normally occurs in a combat situation.

"Even the prison was destroyed," one offical said. "The South Africans invaded this town in 1981, and whatever they left standing that time when they withdrew was destroyed this time. It is vandalism of a strategic kind, since they know it will harm our economy to have to reconstruct everything."