There were growing indications today that a compromise has been reached between the government and opposition forces to try to avoid a potential bloodbath during planned demonstrations in Iran this weekend.

Karim Sanjabi, Iran's leading moderate opposition figure, who was released Wednesday from a month's detention, said that he still refused to enter any coalition government under Shah Mohammad Reza Pahlavi.

Although Sanjabi said his release was "unconditional," it was apparent that at least tacit understanding has been reached under which the government will allow the religious and political opposition to go ahead with plans for massive street demonstrations despite a government ban, provided that they are kept peaceful.

Despite this development, Americans continued to pour out of the country in fear of bloodshed over the Sunday-Monday holiday period of Ashura, a volatile time of religious mourning and political protest for Iran's Shiite Moslems.

Nearly 2,000 dependents of the 800 American military advisers have been authorized by the Pentagon to leave if they so desire, although no special flights have been planned. In the last two months more than 5,000 of the 45,000 Americans in the country have left.

A government order closing all schools until next month has speeded the temporary departure of Americans, while they wait to see if the situation settles down.

[Officials at Tehran's Mehradab Airport reported "utter chaos," according to the Associated Press. Thousands of persons scrambled for plane tickets after airlines announced that they had canceled flights in and out of the city Sunday and Monday.]

[Large groups of U.S. dependents arrived in Tehran from turbulent provincial areas as major American companies such as General Electric, Westinghouse, Fluor Corp. and others evacuated their employes' families, AP reported. At least two American companies chartered planes for employes' families when the airlines reported that all scheduled flights were filled.]

The mood in Tehran is one of gloom and apprehension. Black mourning flags hang in most streets, and people have been lining up for gasoline, heating oil and food all over the city.

One of the hottest selling items seems to be plastic jerry cans, whose buyers evidently anticipate shortages of fuel to grow more severe in the days ahead as oil workers continue to walk off their jobs in a spreading protest strike.

Crude oil production in Iran's southern oil fields was reported at less than 2.8 million barrels today, continuing a steady decline this week caused by a new strike.

Opposition sources said that while there is no firm agreement with the government over trying to avert weekend violence, the two sides have an "understanding" based on "some unofficial contacts" that authorities will not try to forceably stop the march as long as organizers keep it peaceful.

If carried out, this would represent a backing down by the government from a martial law ban on demonstrations but would probably head off a feared cataclysm for the shah.

At a press conference this week, Iran's new military prime minister, Gen. Gholam Reza Azhari, hinted at such a solution.

Asked if he would permit religious processions marking Ashura -- the Shiite mourning day commemorating the death of the prophet Mohammad's grandson, Hossein -- he said, "If they [the opposition] give us assurance they can handle them, we may allow them."

Sanjabi, meeting reporters briefly at his spacious villa in northern Tehran not far from the shah's palace, said, "in the present circumstances we will not enter into a coalition government, nor can we collaborate with one."

The white-haired National Front leader stopped short of seconding the uncompromising demand of exiled religious leader Ayatollah Ruhollah Khomeini for the overthrow of the shah, but he hinted that his departure was the only solution to Iran's crisis.

"The people have expressed their desires by their demonstrations," he said. "Now it's up to the king to conform to the people's wishes."

Most street demonstrations and riots in recent months have been dominated by calls for the overthrow of the Pahlavi dynasty and chants such as "death to the shah."

Asked if he considered it possible for the shah to remain on the throne, even as only a titular head of state, Sanjabi said, "I don't want to reply now."

Some analysts interpret Sanjabi's stance as raising hopes of a political solution once Ashura is over. They cited continuing contact between the government and moderate opposition leaders even while Sanjabi and another National Front leader, Dariush Foruhar, were in custody -- first in solitary confinement in small jail cells for five days and afterward in a comfortable house run by the secret police, SAVAK.

Other political observers viewed any eventual compromise as unlikely, as long as the more radical opponents of the shah continue to dominate the movement against him. These elements, who appear to have broad support in Iran, will accept nothing less than the shah's departure and at present seem to regard the question of what would then follow as a secondary issue.

Sanjabi's more youthful supporters are more explicit in their views of the shah's future. Asked if the man who has ruled Iran for 37 years would be acceptable if he agreed to become merely a reigning "constitutional monarch," one aide said, "I don't think the current shah is able to change his attitude after all these years of violence and repression."

The month-old military government named by the shah after major antigovernment riots Nov. 5 repeatedly broadcast a statement warning the population of plans for sabotage, terrorism and destruction by "the enemies of Iran."

The warning cited leaflets purportedly distributed by two previously unknown communist groups, ordering followers to "carry out a war of nerves through sabotage and destruction aimed at the country's economic, political and social life." Among other methods mentioned were "throwing bombs and grenades into crowds" and "attacking police and soldiers with knives, clubs, firearms and acid."

The government said the documents advised men to conceal weapons under head-to-toe black veils normally worn by devout Iranian women.

Opposition sources charged the leaflets were a government invention.