JOHANNESBURG, AUG. 6 -- South Africa and Mozambique agreed today to set up a joint commission to investigate a massacre last month in Mozambique, in which the Maputo government has charged more than 400 civilians died, and to review the overall security situation in southern Africa.

In another development, diplomatic sources said today that a team of military attaches from several western embassies had flown to Mozambique to investigate the massacre.

The agreement between South African Foreign Minister Roelof F. (Pik) Botha and Jacinto Veloso, minister of cooperation in the Marxist government of Mozambique, represented a major breakthrough in attempts to smooth relations between the two countries following allegations by Mozambique that South Africa was indirectly responsible for the July 18 massacre in the coastal town of Homoine.

Relations between the neighboring states had already deteriorated following unsubstantiated charges last year by Mozambican officials that South Africa was responsible for a plane crash on the border that killed Mozambican President Samora Machel and some of his top advisers.

After a three-hour working lunch today at Botha's Cape Town home, both ministers said they had agreed to the creation of a joint commission to investigate whether there had been any South African complicity in the Homoine massacre, which wounded survivors blamed on anticommunist rebels who have been battling to overthrow the Mozambican government of Joaquim Chissano.

The rebels of the Mozambican National Resistance movement, which is known by its Portuguese abbreviation, Renamo, were supported openly by South Africa until 1984. Mozambique has contended, and Pretoria has denied, that South Africa continues to provide covert aid to the Renamo guerrillas.

Wounded survivors of the massacre said in interviews in a provincial hospital in Inhambane last month that about 400 Renamo guerrillas shot and bayoneted civilians during a five-hour attack. They said many of the victims were women and children slain in their beds in a village hospital.

The official Mozambican news agency AIM said today the official death toll had risen to 408 following the discovery of bodies of people who had fled into the bush after being wounded in the attack.

Spokesmen for Renamo in Lisbon first denied that the massacre had taken place, but later said it had been carried out by a Mozambican Army unit specially trained by North Korean advisers to commit atrocities and make them appear to be Renamo operations. The Renamo spokesmen have most recently claimed that the villagers were killed in cross fire during a mutiny in which Mozambican Army regulars and a home guard militia clashed.

The Homoine attack came as conservative members of the U.S. Congress, led by Sen. Jesse Helms (R-N.C.), launched an effort to gain American support for Renamo.

Today's talks in Cape Town represented the first formal contact between South Africa and Mozambique since Machel's death last year in an airliner crash that Mozambican officials attributed to a false directional beacon placed on the border by South African agents.

A South African commission of inquiry, on which several leading international aviation experts sat, including former U.S. astronaut Frank Borman, absolved South Africa of blame and attributed the crash to errors on the part of the Soviet crew flying Machel's plane.

Today's meeting in Cape Town came two years after Mozambique unilaterally withdrew from a joint security commission established when the two countries signed the 1984 Nkomati Accord. In that mutual nonaggression pact, South Africa agreed not to interfere in Mozambican affairs and Mozambique agreed to expel hundreds of members of the outlawed African National Congress and prevent them from crossing the border into South Africa.

The purpose of the joint security committee was to investigate violations of the accord and discuss matters involving mutual security.

Relations between South Africa and Mozambique almost dissolved following the discovery of military diaries at Renamo's bush headquarters in Gorongoza in 1985. The diaries appeared to document continued South African military assistance to Renamo after the signing of the Nkomati Accord.

The Mozambican news agency has charged that Renamo rebels who had been infiltrating into the Homoine area recently received five parachute drops of arms and supplies from South African planes. In response, the South African Foreign Ministry said, "The South African government has repeatedly stated that it is not providing assistance of any kind" to Renamo.

A key witness to the killings was an American agronomist, Mark Van Koevering, who was serving with a Mennonite Church project in Homoine and who said he watched from a hotel window as Renamo guerrillas killed civilians.

Mozambican officials said that more than 3,000 civilians fled Homoine in fear that the attackers might return.

The Associated Press reported the following from Washington:

U.S. officials said Thursday they think Mozambique's claim that 408 people died in a village massacre may be exaggerated, but they have no evidence to contradict assertions that Renamo rebels were responsible for the attack.

What happened in the agricultural village of Homoine on July 18 has become an issue in Congress, where conservatives opposed to the leftist government have raised questions about the attack.

"We don't have absolutely conclusive evidence about what happened," said one State Department official, speaking on condition he remain anonymous.

"There was no question there was a massacre," this official said. But the death toll may have been lower than 400, probably "more like 100 or 150."

Another official, also speaking anonymously, said, "400 seems high."

Van Koevering, interviewed by telephone from Swaziland, said there is "no question" that Renamo carried out the attacks.

He said he saw 40 to 50 corpses during a three-day period, but, after talking to villagers, believed the figure of 400 dead was realistic.

The agriculture worker also said the rebels have no support among the population in the region where he worked.