MOSCOW, OCT. 1 -- The Soviet legislature today gave final approval to a law guaranteeing freedom of worship, ending decades of state control of religion and persecution of church activists.

The legislation, endorsed in principle last week by the legislature, or Supreme Soviet, cleared its final hurdle today after lawmakers rejected an appeal to allow state schools to provide religious instruction.

They also approved a provision blocking the institution of religious services in the armed forces.

"This is a very important law closely concerning millions of people and a big step toward implementing political reform in our country," said Anatoly Lukyanov, chairman of the Supreme Soviet, after the bill's approval by a 341 to 2 vote.

The law on "Freedom of Conscience and Religious Organizations" allows individuals to determine freely their attitude to religion and provides for the separation of church and state. It proclaims all faiths equal and pointedly does not place atheism on an equal footing with religion, as does the Soviet Union's 1977 constitution.

In line with Karl Marx's denunciation of religion as the "opiate of the masses," atheism has been official policy since the foundation of the Soviet state in 1917.

The new law prohibits the state from intervening in church affairs or financing church activities.

It also bans religious organizations from taking part in the activities of political parties, although clergymen are allowed to run for elective office.

Passage of the measure is the culmination of a new relationship between church and state that has developed over the last five years.

Since President Mikhail Gorbachev came to power in 1985 as head of the Soviet Communist Party, Russian Orthodox Church members, Baptists, Jews, Moslems and adherents of other religious groups have played an increasingly prominent role in public life.

Hundreds of churches confiscated by the state and used for decades as warehouses or museums have been returned to their original owners and refurbished. Sunday schools have opened and the number of baptisms has soared.