By Dmitry Solovyov

ALMATY (Reuters) - Kazakh President Nursultan Nazarbayev signed a tough religion law Thursday including a ban on prayer rooms in state buildings, aimed at stamping out Islamist militancy but criticized by Kazakhstan's top Muslim cleric and the West.

Nazarbayev, 71, has ruled Kazakhstan for more than 20 years as a secularist autocrat. Until this year, the 70 percent Muslim country largely avoided the Islamist violence seen in other central Asian ex-Soviet states like Uzbekistan and Tajikistan.

But a suicide bombing in May and the arrest in August of a group accused of a terrorist plot raised fears of a surge in militancy, prompting Nazarbayev to call for the new law to help curb extremism.

"The new law ... more clearly defines the rights and duties of religious organizations and outlines the role of the state in strengthening the religious tolerance of our society," Nazarbayev said Thursday during a visit to Shymkent, near the border with Uzbekistan where radical Islam is on the rise.

"Peace and harmony in our multiethnic home are Kazakhstan's most valuable patrimony," he said. The comments were reported on his official website.

The law, swiftly approved by the compliant legislature, has caused heated debate. Article 7 bans prayer rooms in all state institutions. Kazakhstan's Supreme Mufti, Absattar Derbisali, said this could anger pious Muslims and spur extremism.

The law also requires all missionaries in the country to register with the authorities every year.

Rights groups in the West, including the Organization for Security and Cooperation in Europe, have raised concern that it may restrict religious freedom.

Among recent measures to fight Islamist militancy, Kazakhstan temporarily blocked access to a number of foreign Internet sites in August after a court ruled they were propagating terrorism and inciting religious hatred.

(Reporting by Dmitry Solovyov; Additional reporting by Olga Orininskaya; Editing by Peter Graff)