South Africa's racial conflict spilled over its borders today with a coup that toppled the civilian government of Lesotho and sent a message to the region's other black-ruled states that they, too, could be swept up in events as the struggle over white-minority rule deepens.

The military coup, announced early this morning on state-run Radio Lesotho, marked the first time in southern Africa's postcolonial history that a civilian government has been overthrown. It followed a week of mounting civil unrest triggered by a virtual economic blockade of the small, landlocked kingdom by South Africa, which encircles it.

The coup was carried out by military leaders reportedly dissatisfied with Prime Minister Leabua Jonathan's refusal to meet Pretoria's demand for ending the blockade: that Lesotho cease to give sanctuary to political refugees fleeing South Africa. Jonathan's ouster already is seen as a warning to other black governments to end support for refugees linked to the outlawed African National Congress, the main insurgent movement seeking to topple white rule.

Jonathan had appealed to the West at a press conference yesterday for an emergency airlift. He expressed surprise that he had received no response from the United States and Britain to his plea for aid and threatened to turn to the Soviet Bloc for help.

Analysts here believe that threat may have triggered the coup by conservative military leaders who are believed more willing to comply with Pretoria's demands. Pretoria has denied any role in the coup.

Many expect the new leaders of Lesotho to agree to a pact with Pretoria, similar to that signed secretly by Swaziland in 1982, that would grant South African police the power to monitor refugees in Lesotho.

The streets of Maseru, Lesotho's capital, were reported empty tonight after a dusk-to-dawn curfew was imposed, following a day of mixed celebration and fear. The coup itself was apparently bloodless, although at least five soldiers died in clashes last week between rival military factions.

Jonathan's government, which has ruled this country of 1.4 million people since it gained independence from Britain in 1966, was replaced by a military council reportedly headed by Maj. Gen. Justin Lekhanya, head of the country's paramilitary force. Radio Lesotho said Lekhanya had pledged to retain King Moshoeshoe II as the country's symbolic leader.

Others on the ruling council were said to include the officers commanding the kingdom's security force and its police, both of whom had joined Lekhanya in talks Friday in Pretoria that failed to persuade the South Africans to ease their sanctions. But by evening Lekhanya had not yet appeared nor spoken publicly.

Jonathan was reportedly at his mountain retreat outside the capital, while some Cabinet ministers were said to have fled the country.

While denying any role in the overthrow, South African officials applauded the change. Foreign Minister Roelof F. (Pik) Botha was quoted by the government-controlled radio network as calling Jonathan "the biggest single destabilizing factor in Lesotho." He said South Africa "welcomes any lessening of tension in Lesotho.

Later in the day, South Africa relaxed its strict border controls and allowed a train carrying fuel to enter Lesotho.

Zimbabwe's government had no official comment on today's coup. But a Zimbabwean official, speaking not for attribution, said that the coup would have "serious implications for the rest of the region. Obviously the South Africans wanted to make Lesotho an example and they've done it in an extremely nasty way," he said. "Obviously the next likely target will be Botswana. Will we be next after that? I hope not."

President Samora Machel of Mozambique, whose Marxist government two years ago concluded a nonaggression pact with Pretoria, said in a speech during the weekend that South Africa viewed his government as "a target to be shot down." Mozambique, he said, faced "constant aggression through armed bandits supported, trained, equipped, supplied and financed" by South Africa.

For many years the autocratic Jonathan, who suspended free elections in 1970 and was widely viewed as the region's most conservative black ruler, was a South African favorite. But that changed as pressure on his nation increased and he appealed to both the West and, in recent months, the East Bloc, for support against Pretoria.

Lesotho has always been one of South Africa's most vulnerable neighbors. More than half its gross national product is derived from earnings of workers from Lesotho employed in South Africa, and 97 percent of its imports pass through there.

Pretoria, alleging that ANC guerrillas launch raids from Lesotho, periodically has choked off road and rail traffic. In 1982 South African commandos killed 30 refugees and 12 Lesotho citizens in a raid on alleged ANC strongholds.

While welcoming refugees, Lesotho has denied that it allowed them to conduct operations against South Africa from its territory. In recent years it has sought to airlift most refugees to other African states to meet South Africa's demands.

Lesotho's latest troubles have been a consequence of the upsurge of guerrilla violence in South Africa. About a dozen white civilians have died in explosions of land mines and bombs, and ANC President Oliver Tambo recently pledged to intensify such attacks.

After the land-mine explosions in the northern Transvaal, Pretoria threatened to attack Zimbabwe, a warning that set off a brief panic here. South Africa's State Security Council in December accused all of its neighbors, including Botswana, Mozambique, Zambia and Swaziland as well as Zimbabwe and Lesotho, of harboring "terrorist elements."

Earlier, unidentified white gunmen entered Lesotho and killed six ANC members and three Lesotho citizens in a raid that Jonathan blamed on South Africa.