NAIROBI, KENYA, FEB. 5 -- The government of Kenya, which today released nine political prisoners who had been held without trial for up to six years, appears to have embarked on a major effort to clean up its tarnished human rights record.

The surprise release followed a number of steps by the government in recent months to overhaul the country's internal security apparatus and allow the court system to expose cases of political prisoners who were allegedly tortured and died while in police custody.

The international image of this East African country, long regarded as a peaceful, prowestern democracy and a stable haven for tourists, suffered a painful pounding in the past year. Among other alleged abuses, the Kenyan government was accused by human rights organizations of using torture to coerce confessions from more than 75 political opponents.

Kenyan President Daniel arap Moi, who personally controls almost all political and police power in this country, was hounded during his foreign travels in 1987 by press accounts of such abuses.

In Washington last March, the human rights issue was discussed in Moi's private meeting with President Reagan. Possibly fearing bad publicity and demonstrations, Moi last fall canceled an official visit to the three Scandinavian countries that are Kenya's most generous aid donors.

For the most part, Moi's response to outside criticism has been indignant rage. In December, he told the London-based human rights group Amnesty International, which had written a documented report on torture in Kenya, to "go to hell." The president threatened to arrest personally any representative of the group who came to Kenya.

But a pattern of decisive moves here recently appears to signal a desire by Moi's government to clean up its image and placate western donor countries that have complained about abuses here.

The most dramatic airing of the government's actions took place late last month in open court.

A lawyer detailed how national police allegedly tortured a suspected political dissident to death while he was in their custody.

This "is a sad case of functionaries of the state system gone crazy with unchecked power," said lawyer Ooki Ooko Ombaka, who is representing the dead man's family in an inquest.

Under Kenyan law, Peter Karanja should have been brought before a magistrate within 24 hours of his arrest last February. Instead, 24 days after police picked him up as a suspected subversive, he was wheeled into a Nairobi hospital where he died of massive internal injuries.

"Because the special {police} unit which arrested and interrogated Mr. Karanja flagrantly violated the laws of this land," said the lawyer, "the responsibility {for his} death must surely rest with the unit and vicariously with the state in whose name they operated." The bluntness of the lawyer's words and the fact that they were reported in detail in the government-controlled press surprised and pleased western diplomats and local lawyers who specialize in human rights cases.

"The mere fact that the inquest is going on is an indication that there are senior people in the government who want to correct the excesses of 1986 and early 1987," said Murungi Karaitu, one of Kenya's most outspoken human rights lawyers.

According to diplomats and lawyers, there have been other signs of a new-found concern for human rights in Kenya.

They include the release this week of 10 political detainees, who had been held without trial under a law that denied them regular visits with their families or access to an attorney. Most of the detainees had been accused of involvement with Mwakenya, an underground organization that the government feared was trying to destabilize the country.

Ngotho Kariuki, a former University of Nairobi lecturer and one of nine detainees released this morning, said he had been tortured while in custody. He said he was confined for extended periods to a dark cell that was partially filled with water and was repeatedly beaten during interrogation.

Another of those released today was Raila Odinga, son of Kenya's best known opposition politician, Oginga Odinga. He had been held for six years in connection with an unsuccessful coup by junior Air Force officers.

Late last year, Moi also ordered that Gibson Kamau Kuria, a prominent human rights lawyer, be released from jail. He had been detained nine months earlier when he filed suit on behalf of three political detainees who said police had tortured them to extract confessions.

"The impression I am getting, the way this matter is being approached by the government, is that everyone is now concerned to see that the law is followed," Kuria said this week.

Two recent high-level changes in Kenya's security apparatus -- the transfer of the powerful head of internal security and the firing of the commissioner of police -- suggest that Moi is committed to his recent promise "to purge the {police} force of elements that tarnished the government's image."

Justus Ole Tipis, the 74-year-old internal security chief who was thought to have had close ties to Moi, had been the most clamorous senior official in the Kenyan government in condemning outside criticism of human rights abuses.

Tipis abruptly lost his position last month after an embarrassing incident involving U.S. citizens. Security police picked up and interrogated two Americans, a retired federal judge and a Chicago pathologist, who had come to Nairobi to observe the Karanja torture trial.

The commissioner of the National Police Force, Bernard Njiinu, was fired in January. Under Njiinu, charges of torture and corruption in the police department had become widespread. His replacement, Philip Mule Kilonzo, has a better reputation and has been empowered by Moi to clean up the police force.

According to Kuria, the released lawyer, Kilonzo is "fair and complies with the law as he understands it."

In what may be the most significant sign of the government's new attitude toward human rights, the number of arrests of dissidents and reports of torture have dropped sharply, according to western diplomats and informed local sources.

"We don't have indications that the abuses noted in the Amnesty report are continuing with the same frequency," said a western diplomat.

While diplomats and local lawyers agreed that there has been an improvement in the government's human rights record, they cautioned that Kenya remains a state where, in practice, police are rarely punished for beating up or torturing prisoners.