JOHANNESBURG, South Africa - A soldier helping police quell violence against foreigners in South Africa shot and killed a man who was attacking a woman, the military said yesterday, as hundreds more immigrants fled the country.

Police also fired rubber bullets to disperse crowds as sporadic violence and looting were reported across the country in the latest disturbances, which have left at least 42 people dead and more than 25,000 foreigners displaced this month.

Much of the violence is fueled by resentment of immigrants competing for scarce jobs and housing. Others blame foreigners for crime. Seeking to calm the unrest, President Thabo Mbeki called in the army on Wednesday for the first time since the end of apartheid in 1994 to aid police.

Mbeki condemned the violence, saying during an appearance at a school in eastern South Africa that it disgraced the legacy of the liberation struggle, the state broadcaster reported yesterday.

On Friday night, soldiers supporting police east of Johannesburg saw a man assaulting a woman, Brig. Gen. Kwena Mangope said. As they approached, the man pointed a gun at the soldier, who then shot the man, Mangope said.

It was not clear whether the assault on the woman was related to the recent violence against foreigners or was a domestic dispute.

Mangope said the incident was "unfortunate" and that police were investigating.

Safety and Security Minister Charles Nqakula acknowledged that putting soldiers on the streets was sensitive since they were trained to kill, not to enforce the law. He said they would only support police, who have made more than 500 arrests linked to the antiforeigner violence.

The minister visited several hot spots yesterday with a high-level government delegation. The center of the violence has been the country's smallest but richest province of Gauteng, which includes Johannesburg.

Gauteng provincial police spokesman Govindsamy Mariemuthoo said there were a number of minor incidents overnight in the province's East Rand area, which has seen the worst of the violence.

He said police used rubber bullets to disperse crowds but no deaths were reported.

By Friday, violence had spread to at least seven of the country's nine provinces as well as the popular tourist destinations of Cape Town and Durban.

A Cape Town police spokesman, Andre Traut, said police had been called to a number of areas overnight to stop looting of shops and help move foreigners.

"But everything is back to normal now, and there is no violence," Traut said.

About 200 people have been arrested, while about 1,200 people had been displaced in Cape Town, he said.

While the violence was dying down, thousands of displaced remained in camps, and foreigners were streaming back to their home countries.

Immigration officials in neighboring Mozambique said 2,000 Mozambicans crossed back home yesterday morning. In total, the number of Mozambican immigrants who have fled South Africa now stands at 16,000, and more were expected.

Malawi, another South African neighbor, said Friday it had rented a bus to bring citizens home from South Africa.