President Mikhail Gorbachev may fail in his daunting task of rescuing the Soviet Union's failing economy. He may be replaced by the political process or by a much-rumored military coup.

But whatever Gorbachev's fate, his place in history is secure, thanks to one monumental achievement: ending 73 years of official communist persecution of religion and embedding freedom of conscience in the law.No matter what kind of regime succeeds Gorbachev's - hardline communist, nationalist, military-fascist, democratic - it is highly unlikely to reverse the tolerance of religion he has nurtured in his five years in power.

Communism's cruel hostility to belief and worship can be traced to Karl Marx's crabbed view of religion as the "opiate of the masses." This was accepted (ironically, as an article of faith) by V.I. Lenin and his odious successor, Josef Stalin.

After the 1917 Bolshevik coup, priests were murdered, jailed and exiled. Church property and places of worship were seized, torn down or turned into warehouses, stables or "museums of atheism." Those brave enough to profess their faith were barred from the Communist Party and decent jobs.

In 1929, Stalin outlawed religious teaching, which he called "propaganda." In 1932, he decreed an "anti-religion five-year plan."

Moscow boasted that by 1937 "not a single house of prayer will be needed any longer in the territory of the Soviet Union, and the very notion of God will be expunged as a survival of the Middle Ages and an instrument for holding down the working masses."

Fortunately, Soviet five-year plans never succeed. But Stalin's war on religion came close. For instance, of the 54,174 Russian Orthodox churches in use in 1917, fewer than 100 were open in 1939.

To help save his brutal regime in the war with Hitler, Stalin promoted "Russian" nationalism and let up on the Orthodox faith. But after the war he resumed his habit of dispatching clergymen and religious activists to the gulag.

Though he is the son and grandson of party members, Gorbachev was baptized as a child. His mother attends Orthodox services. Gorbachev made both facts public last year. To do so earlier would have impeded his party career.

To his credit, Gorbachev saw that religious persecution violated his own goals of glasnost and limited democracy. In the last three years, more than 4,000 buildings have been returned to the Orthodox Church alone. Bibles and Korans are printed and imported. Patriarch Alexei II and other clergymen sit in the Soviet Parliament, something unimaginable in the past.

On Oct. 2, parliament codified Gorbachev's de facto religious tolerance. In a historic 341-2 vote, it guaranteed the right to adopt, practice and proselytize any creed. It allows religious teaching and charitable work. While the law does not restrict atheism, it directs the government to stop promoting it.

For seven decades the communists have hailed their coup - against Russia's only freely elected government - as the Great October Revolution. One suspects that this October's religious revolution will prove more durable.