South Africa, faced with strong international condemnation and a warning from the Angolan government that a major clash with its forces was imminent, announced tonight that it is withdrawing its troops from southern Angola.

Gen. Constand Viljoen, chief of the South African Defense Force, said his unit of about 500 men had completed its preemptive strike against Namibian insurgents who were operating inside Angola and allegedly planning strikes into the South African-controlled territory of Namibia. Viljoen said his forces would pull back to bases in Namibia "before the end of the weekend."

He made no mention of an earlier Angolan Defense Ministry statement charging that South African forces had penetrated 150 miles into Angola and were preparing to confront Angolan soldiers advancing on Jamba, the military headquarters of Jonas Savimbi's antigovernment Union for the Total Independence of Angola (UNITA). Savimbi's forces have been battling the Marxist government of Angola for 10 years.

In a further sign of deteriorating relations between white-ruled South Africa and its black neighbors, top South African and Mozambican officials met urgently today to discuss new allegations that the Pretoria government has violated the nonaggression pact between the two nations by aiding Mozambican rebels.

South African officials acknowledged some of the activities charged by Mozambique but played down their significance, countering with charges that rebels seeking the overthrow of white-minority rule in South Africa still are operating from Mozambican territory in violation of the accord.

The partial acknowledgment of Mozambique's charges comes at an embarrassing time for the Botha government, as Mozambican President Samora Machel met in the White House today with President Reagan.

The South African raid into Angola, which began Monday, has prompted widespread western protest, including some of the strongest statements to date from the Reagan administration accusing Pretoria of violating international law by its military operation and its continued presence in Namibia. South Africa administers Namibia despite U.N. votes revoking its mandate to do so.

The new incursion, which began only a week after the return to Pretoria of U.S. Ambassador Herman Nickel, is widely seen here as a slap at the United States following Reagan's announcement of limited economic sanctions. Analysts noted that Nickel had been recalled to Washington in June to protest South African commando operations in neighboring Botswana and Angola.

South Africa has insisted from the incursion's beginning that it was aimed at preempting an offensive by rebels of the South-West Africa Peoples Organization (SWAPO), which has been fighting a bush war from Angolan bases against South African rule in Namibia.

In his statement tonight, Viljoen said South African forces had succeeded in disrupting SWAPO supply lines and destroyed large amounts of weapons and ammunition. He said two insurgents had been killed and others had fled north. He reported no South African casualties.

The Angolan statement painted a far different picture, saying South African armored vehicles had moved within 10 miles of Mavinga, a southeastern town believed to be near Jamba, Savimbi's secret base.

Angola said South African forces, with troop carriers, artillery and grenade launchers, were "ready to be brought into combat against our troops operating in that direction." It said the operation was "aimed purely and simply at saving UNITA," which has been under attack by Angolan forces.

Despite denials, South Africa long has supported Savimbi's forces with arms and other supplies. The Angolan offensive appeared designed to cut off UNITA's supply lines to Namibia. A South African medic attached to UNITA was reported killed over the weekend in a skirmish with Angolan forces.

Angola also said South African air raids had killed six Angolan troops and injured 25 earlier this week. A South African military spokesman would not comment on the Angolan statement.

Meanwhile, Foreign Minister Roelof F. (Pik) Botha and Defense Minister Magnus Malan flew to Komatipoort, scene of the signing last year of the nonaggression pact with Mozambique, for emergency talks with Mozambican officials following new allegations of South African military support for the Mozambique National Resistance movement, which is fighting the Marxist government there.

Botha has confirmed that on Monday Machel presented him with documentary accounts of South African Air Force flights and supply drops of weapons, ammunition, blankets, radios and compasses to the rebel field headquarters in Gorongoza, as well as secret visits to the rebel base by Deputy Information Minister Louis Nel.

He said Machel characterized the activities as "more than a breach" of the accord and told Botha that the joint commission set up to monitor the pact should be suspended.

The accounts were in documents captured recently when a joint Zimbabwean-Mozambican force overran the Gorongoza base in Sofala Province, according to Mozambique. They included a diary with dates and details of supply drops and meetings between rebel leaders and South African officials.

Botha told reporters that the allegations were "technically" correct but denied that his government's actions had violated the accord.

He said South Africa had flown a "limited quantity" of arms to Gorongoza in August to protect South Africans building an airstrip there to monitor a proposed cease-fire between Mozambique and the rebels. He said further "humanitarian assistance," including money, medicine and gasoline, had been given the rebels.

Botha said tonight that he had given Mozambique an explanation and also had "conveyed details about the presence of African National Congress members in Mozambique." He did not elaborate. The removal from Mozambique of agents of the main rebel movement fighting white rule in South Africa was a prime objective of the pact.