MAPUTO, Mozambique (AP) _ Several thousand youths ransacked Malawi's embassy and stoned South Africa's trade mission Tuesday to protest the death of President Samora Machel, witnesses said.

Reporters at the scene said police used tear gas and fired warning shots to disperse the first violent demonstration reported in Maputo since Machel led Mozambique to independence from Portugal in 1975. He was killed in a plane crash Oct. 19 just across the border in South Africa.

Windows were broken at the South African mission, but police kept the rioters from getting inside, the witnesses said. A slogan scrawled on an outside wall said: ''Machel's death will be avenged.''

At the Malawian Embassy a few blocks away in central Maputo, invaders destroyed furniture and burned the Malawian flag, the official Mozambican News Agency reported.

A slogan written on a wall said ''Banda is a murderer,'' a reference to President H. Kamuzu Banda of Malawi, the only African nation that has diplomatic relations with South Africa.

Security Minister Sergio Vieira stood atop a truck that drove among the rioters, pleading for calm. ''Breaking windows is not a revolutionary act 3/8'' he called to them. ''Comrades, I want you to behave as disciplined Mozambican citizens 3/8''

Mozambique accuses South Africa of aiding the rebel movement fighting its Marxist government and claims Malawi harbors the guerrillas.

President Kenneth Kaunda of Zambia and Prime Minister Robert Mugabe of Zimbabwe have suggested that South Africa bears responsibility for the plane crash that kills Machel. South Africa denies it, and Mozambique has not commented officially.

No injuries were reported in the rioting Tuesday and it was over by midafternoon, journalists said. Soldiers and police surrounded offices of South African Airways in case of an assault.

In Pretoria, South Africa, Foreign Minister R.F. Botha said he would discuss ''the implications of this hostile and reprehensible display'' with Mozambique's government. He said he had requested protection for South African offices and personnel in Maputo.

He estimated that about 3,000 young people marched on the South African mission, then sacked the Malawian Embassy.

Botha said the crowd increased to about 5,000 and returned to the South African mission. He claimed police did not try to stop the crowd immediately.

It was the second time in two weeks that South African and Malawian offices in southern Africa were damaged by rioters angered at Machel's death.

Soon after the plane crash, crowds in Harare, Zimbabwe, attacked South African and Malawian airline and diplomatic offices and stoned the U.S. Embassy.

Police in Lesotho broke up a protest march, arresting scores of youths, and in South Africa police used tear gas to disperse a university demonstration five days after Machel's death.

In Maputo on Tuesday, the youths responded to the security minister: ''Vieira, our friend, the people are with you 3/8'' but only ''rapid intervention police'' kept them out of the South African trade offices, the national news agency reported.

It said the special police, normally feared by civilians, were visibly moved when the youths chanted: ''Father Samora said the struggle goes on 3/8''

According to the agency, the high school students and other youths had assembled for a demonstration to protest Machel's death and had intended to deliver messages to the South African and Malawian missions.

One youth leader was quoted as saying the Malawian Embassy staff refused to accept the message and, as the crowd moved away, some youths overwhelmed police and burst inside.

The protest occurred a day after Foreign Minister Joaquim Chissano was named by the central committee of Frelimo, the ruling Marxist party, to succeed Machel. Chissano, 47, was chosen by acclamation, without a formal vote.