PESHAWAR, PAKISTAN, JAN. 8 -- Mohammed Hassan Kakar, for five years a political prisoner in Afghanistan, recalls his first days in a secret police prison with a tremor of fear in his voice.

"It was a dirty room of only 10-by-12 feet with one window high up on the wall. Sometimes I was alone. Sometimes there were two or three other people. There was no exercise outside, no reading material, no visitors. We could go to the bathroom only three times in 24 hours. Suddenly, being confined like that, it was agonizing. It went on for nine months," the soft-spoken professor said in his first interview since escaping to Pakistan following his release from prison.

Hassan Kakar, 53, a western-trained history professor, explained how he came to be considered a threat to the Soviet-backed Afghan government.

After seven years of study in London, where he received his doctorate, and 3 1/2 years at Harvard as a research scholar, he thought he was finally in a position to repay a government and society that had financed his rare western education after his parents had died.

He was the head of the history department at Kabul University when the revolutions of the 1970s began to convulse Afghan society. At first, he was determined not to be a part of it, but to continue to do what he thought he could do best -- teach history.

"When I saw the first Russian tank in Kabul, deep down I felt the time had come that I could not just confine myself to the academic field, that Afghanistan needed more. I was not alone. There were friends who felt the same," he said.

He and friends began to organize at Kabul University. There were study groups, leaflets and support for student activists and others.

"Many university professors left at this time. Students were arrested. But I felt that at least we could provide a symbol of resistance," he said. Then, on April 1, 1982, he was arrested.

Friends and family had urged him to leave the country, and he almost had, but finally he decided that he could not.

"As an Afghan, I felt disgraced to leave because of these guys. Second, I felt morally responsible having had an education that not many Afghans had, and finally, as a student of modern Afghan history, as a scholar, I was more interested in the developments going on around me," he said.

When his trial began a short time after his arrest, he faced almost a dozen charges, including plotting to overthrow the government, being pro-West and anti-Soviet, editing a clandestine journal and organizing professors. At least two of the charges carried the death penalty.

He was sentenced to eight years in prison, but it was the first part that was most agonizing, the nine months in the small cell at the headquarters of the secret police, Khad.

"The isolation, this was the most terrible punishment. . . . There was no outlet for inner feelings. It seemed it was their purpose to break a person and reduce him to insignificance. They did not succeed," he said with a note of pride in his voice.

"To have hope, to believe your course is right, gives courage."

While he was not tortured either during his stay at Khad headquarters or during four years at the notorious Pul-i-Charki prison on the outskirts of Kabul, he said many others were. Torture was more brutal, he said, during the early years when the Khalq faction of the People's Democratic Party of Afghanistan was in power.

"The Khalqis were simply brutal. They would just beat people and didn't care. Under the Parchamis -- the second faction to gain control -- the principles of punishment were different. It was to break you but not to leave the marks. I saw a man who had a master's degree from an American university. He had been kept sleepless for 42 days. At one point his wife was brought and shown to him and he was told she, too, will be punished if he did not confess to the crimes with which he was charged."

Other accounts about Afghan prisons have reported electric shock treatments, beatings and other tortures. In November, Amnesty International issued a report saying it had evidence that torture is "widespread and systematic" in Afghanistan. On the other hand, a special U.N. envoy, Felix Ermacora of Austria, has reported "some improvement" in the human rights situation there.

For much of his time in Pul-i-Charki, Hassan Kakar recalls being in a room with more than 100 other prisoners. When he first was brought there, he said, it was so crowded that there was no place to sleep. When he finally found a small corner, it was full of lice.

His family and their welfare remained one of his greatest worries while he was in prison, he said. Three of his children were in Peshawar studying or setting up a new life for themselves when he was imprisoned, but his wife and two younger daughters were still in Kabul. While he worried about them, he also said it was they who did much to help him survive, sending parcels with fruit or medicines and vitamins.

Throughout his imprisonment, he later learned, authorities in Kabul and Moscow were being inundated with appeals for his release. Because of his studies in the West, he was known by many in the academic world, and as word spread of his arrest and imprisonment, Amnesty International and others took up his case.

Hassan Kakar said he is not sure how much the letters helped in the early phases, although he noted that two of the crimes with which he was charged did carry the death penalty. Later, he said, he noted a difference after Soviet leader Mikhail Gorbachev began to make changes in Soviet policy and apparently to try to find a way to withdraw its forces from Afghanistan.

Hassan Kakar and three other professors were released in March, in what some observers suggested may have been a gesture to try to improve the atmosphere for negotiations over a Soviet withdrawal. Many other prisoners have been released under amnesties declared as part of the Kabul government's national reconciliation policy, although the policy itself has not been successful in attracting new adherents to the regime.

Once out of prison, Hassan Kakar said he realized that if he was going to be able to help the Afghan resistance, it would have to be outside the country, where he could publish writings about his experiences.

To avoid arousing suspicion, he borrowed money to fix up his house. Then last month, he and his family disappeared from Kabul.

Hassan Kakar arrived here about 10 days ago, followed quickly by his wife and youngest daughter. His 16-year-old daughter arrived yesterday, reuniting the family and making it possible for him to begin to tell his story.