Government agencies do not have "unfettered discretion" to infiltrate religious gatherings as part of criminal investigations, a federal judge ruled this week in Phoenix in a case involving four congregations and two Protestant denominations.

At the same time, Judge Roger D. Strand said that government investigators could infiltrate churches without warrants in certain circumstances, such as a case in which an agent is invited by church members to participate in criminal activities.

The ruling was the latest development in a case that goes back to January 1986, when the four churches and their parent denominations filed a lawsuit charging that the actions of U.S. Immigration and Naturalization Service agents created a "chilling effect" on the free exercise of religion.

The INS agents were part of an undercover operation designed to gather information about the sanctuary movement through which churches have sheltered and otherwise helped Central American refugees who have entered the United States illegally.

The suit was filed by Southside Presbyterian Church in Tucson; Alzona Evangelical Lutheran, Camelback United Presbyterian and Sunrise United Presbyterian churches in Phoenix; the Presbyterian Church (U.S.A.) and the American Lutheran Church, now part of the Evangelical Lutheran Church in America.

In October 1986, U.S. District Judge Charles H. Hardy ruled that the churches had no standing to sue the government because they were not injured when federal agents made secret recordings at worship services because none of the taped material was used as evidence in criminal cases.

However, in March 1989, the Ninth Circuit Court of Appeals said a church does have standing to sue in such a case when it "suffers organizational injury because its ability to carry out its ministries has been impaired."

Strand's ruling was the first on the substance of the complaint. He declared that "the government is constitutionally precluded from unbridled and inappropriate covert activity, which has as its purpose or objective the abridgement of the First Amendment freedoms of those involved."

Although he said a warrant is not necessary if an undercover agent is invited to take part in suspected criminal activities, the judge noted that "the participants involved in such investigation must adhere scrupulously to the scope and extent of the invitation to participate that may have been extended or offered to them."

The plaintiffs had presented evidence that the ministry of the congregations was directly impaired when the surveillance became known. The Camelback and Sunrise churches eventually closed because of a drop in attendance caused by distrust and fear, according to Peter D. Baird, the churches' lawyer.