In an eleventh hour compromise, Iran's embattled military government backed away from the power of the Mosque today and reversed its earlier martial law ban on anti-shah protest marches scheduled for Sunday.

The emerging compromise became apparent earlier in the day when Ayatollah Kazem Shariat-Madari, the most influential Moslem divine inside Iran, lent his decisive authority to the arrangement.

Despite the relief the lifting of the ban provided on the eve of what remains the potentially most explosive moment of the nearly year-long power struggle in Iran, the ayatollah warned that the country's Shiite Moslems might "soon" resort to armed insurrection.

The compromise was announced by Gen. Golam Reza Azhari, the military government's prime minister, over Tehran Radio. While processions have been authorized, he said, neither trucks nor motorcycles could be used by demonstrators.

In several previous demonstrations, such vehicles were used by anti-shah activists to supply crowds with Molotov cocktails and other inflammable material.

Today's compromise, however, does not preclude the possibility of extremists attempting to turn Sunday's demonstrations into riots.

The 76-year-old ayatollah said Moslem believers would not resort to armed insurrection "unless we are finally forced to." But he stressed that Shah Mohammad Reza Pahlavi must accede to Moslem demands for political and constitutional reforms.

"Our arms are our influence with the people," he told visiting reporters. "But if we need them [arms] in the future we will prepare for" armed struggle.

The leader of the country's 32 million Shiite Moslems indicated that the door to dialogue was not yet shut.

"If the government puts into practice the rights of the ulema (religious teachers) we will not take this step," he said, "but if it doesn't, we will have to take steps."

When, he was asked.

"It will be soon," he said.

Shariat-Madari appeared to be warning that opposition pressure will not abate even if there is little or no bloodshed during the 48-hour period of mourning that begins Saturday night and is known as Ashura.

Ashura commemorates the assassination about 1,300 years ago of Hossein, the prophet Mohammed's grandson and founder of the Shiite sect of Islam which is Iran's state religion.

Lying fully clothed on a blanket in his home on the grounds of Iran's most prestigious theological school, the ayatollah credited former prime minister Ali Amini with having worked out arrangements for the peaceful march in Tehran Sunday.

The gist of his remarks was that Amini had succeeded, barring unforeseen developments, in persuading both sides to accept a peaceful march. Atlhough under martial law in force since September all gatherings of more than two persons remain illegal, the government tipped its hand earlier this week.

The black-turbaned ayatollah warned that "the solution of Iran's problems is not connected with Ashura." Rather the solution would come when the government exchanged its "totalitarianism" for "democracy," he said.

The Sunday march, to start from eight separate places and converge on a monument near the airport marking 2,500 years of the country's history, is seen as a mammoth show of force by the religious-dominated opposition to the shah.

Shariat-Madari and two equally prestigious Qom ayatollahs last night issued a statement warning that Iran's "Moslem soldiers" must not open fire on Moslem demonstrators.

"This action is strictly forbidden," the order said.

The shah was reported by insiders to be equally determined to avoid further bloodshed at almost any price.

This forebearance apparently reflects his fears that any further outbreak of mass violence and loss of life could topple him.

"If the situation is very dangerous and many people die, Shariat-Madari said, "The present [military] government cannot survive.

Optimists were cheered by the apparent eleventh-hour meeting of minds. They reasoned that the domestic opposition would also lose if Ashura turns violent. Indeed the only clearly discernible victor would be Ayatollah Ruhollah Khomeini, the Paris-based exile who has sworn to topple the shah.

But as Shariat-Madari said, "We are now waiting for action not promises" from the government.

He made it clear that only the religious opposition counted in his eyes when he brushed aside suggestions that the present military government give way to a civilian coalition regime.

Coalitions made sense only where political parties existed, which was not Iran's case, he said dismissing the dozens of groups advertising themselves as coalitions.

"There is no political party except the nation itself which is following its religious leaders," he said.

As has become his standard line, the gray-bearded religious leader said the government knows full well what it must do to end the political crisis.

"We are now waiting for action, not words and promises," he said.

Indicative of the ayatollah's sense of measured exasperation was a government radio broadcast last week promising respect for religious leaders and specifically a religious veto on any proposed legislation.

That has been a key demand by religious leaders and figures in the 1906 constitution which the shah has systematically stripped of its powers as he increasingly concentrated all authority in his own hands during his 37-years reign.

Ayatollah Shariat-Madari insisted that no government emissary had confirmed the radio broadcast about the compromise and said respect for the constitution was "just giving us our due."

Asked about the rising tide of xenophobiawhich has driven some foreigners out of Iran, he said, "The people generally do not have bad feelings toward foreigners."

"But they have had feelings against foreigners who exploit the country," he added, stressing that those who attacked foreigners and their property were "a minority group" such as could be found in other countries.