JOHANNESBURG, South Africa (AP) _ President P.W. Botha today commuted the death sentences of the Sharpeville Six, the Justice Ministry said. The sentences for the group of blacks had provoked worldwide protests.

The Sharpeville Six, five men and a women, will serve prison terms ranging from 18 to 25 years, the ministry said.

Botha also commuted the death sentences of four white policemen and three black men, all of whom had been sentenced to hang for murder. They were given prison terms ranging from 15 to 25 years.

Two of the policemen were convicted of killing a township youth in the Eastern Cape province after severely beating him. The other two were convicted of carrying out hired killings of two suspected drug dealers in the Soweto township outside Johannesburg.

The president's decision on the Sharpeville Six came hours after the Appeal Court in Bloemfontein, the nation's highest court, unanimously rejected an appeal to reopen the trial of the Sharpeville Six.

The Justice Ministry gave no reason for Botha's decision, and Jack Viviers, a spokesman for Botha, refused comment.

Botha previously had turned down a clemency request, but said he would reconsider the matter ''as a human being'' once the judicial process was completed.

The Sharpeville Six were convicted of murder in connection with the September 1984 mob killing of a black town councilor in Sharpeville, a township south of Johannesburg.

No evidence was presented that the six contributed physically to the death of the councilor, Kuzwayo Dlamini. Instead, they were convicted under the doctrine of common purpose, which held them responsible because they allegedly were active participants in the mob that killed Dlamini in riots caused by a rent increase.

Anti-apartheid groups in South Africa, international human rights organizations and numerous foreign governments have urged Botha to grant clemency.

Appeals for clemency for the six have come from, among others, the United States, Canada, Japan, Britain and most other European countries, and the United Nations. Virtually all prominent anti-apartheid and liberal leaders in South Africa have urged clemency, including Archbishop Desmond Tutu.

Before the reprieve was announced, Prakash Diar, lawyer for the six, the Appeal Court decision was ''a bit disappointing'' but not unexpected. He said a clemency petition would be submitted to Botha within a few weeks.

Defense lawyers had asked that the trial be reopened to hear evidence from a state witness who said police coerced him into giving false testimony against two defendants.

In today's unanimous ruling, a five-judge panel of the appeal court rejected the application. The panel said the trial judge, Willem Human, acted properly and at no time was presented with an affidavit by the witness asserting that he had given false evidence.

Shortly before the Appeal Court heard oral arguments in September, Botha told a television interviewer: ''I cannot interfere with the judicial system in South Africa unless it is completed, and only when it is completed will I, as a human being, deal with this matter on merit.''

Some of Botha's critics have accused him of hypocrisy, noting that he ordered a halt to prosecution of South African soldiers about to go on trial for murder in South-West Africa, also known as Namibia.

The Sharpeville Six are Francis Mokgesi, 31; Reid Mokoena, 24; Oupa Moses Diniso, 32; Duma Joshua Khumlao, 28; Reginald Sefatsa, 32, and Theresa Ramashamola, 27.

Violence against black officials who cooperate with the white-led government's segregated political structures is considered by many blacks to be a consequence of apartheid.

The Sharpeville Six were convicted of murder in 1985 and have spent 1,076 days on Death Row.

The riots in Sharpeville and neighboring townships in September 1984 marked the start of more than two years of nationwide black unrest.

Under apartheid, South Africa's 26 million blacks have no vote in national affairs. The 5 million whites control the economy and maintain separate districts, schools and health services.