"Another six months and it will be total anarchy. We may be in the middle of another Beirut in a year."

The concern voiced by an establishment figure in Iran is indicative of a growing fear among moderates - both for and against the shah - that things are getting out of hand.

This year's almost continuous civil unrest in this oil-rich country stands in sharp contrast to a quarter century of authoritarian rule by Shah Mohammad Reza Pahlavi.

As the unrest continues without any sign of abatement, there is a mounting fear even among moderate opposition leaders that they are caught between two extreme forces: the shah, who will not make enough meaningful compromises soon enough, and the exile Moslem religious leader Ayatollah Ruhollah Khomeini, 78, his long-time enemy.

The fear is that the shah will turn matters over to a military government in the face of Khomeini's continuing demands for his ouster.

Either result could cause considerable tremors in the West where Iran with its 1,500-mile border with the Soviet Union, has long been regarded as southern bulwark against Soviet expansionism.

Iranian specialists worry about the destablizing effect the shah's downfall could have on politically vulnerable Pakistan and the weak Persian Gult oil sheikdoms. A new factor in the potential for East-West trouble is the new pro-Soviet government of Afghanistan.

A harsh military government, however, could lead to a quickening of the tempo of disintegration which to many is already frightening.

Typical comments from dozens of interviews were: "The whole situation is out of control." "The opposition doesn't know what it wants." "No one knows where we are going."

Although there has long been student and leftist opposition to the shah, his most significant opponents are the Moslem religious leaders opposing his westernization plans. They are headed by Ayatollah (religious leader) Khomeini, who was banished from Iran after an abortive coup in 1963 and now lives near Paris.

So frightened of military takeover are even moderate opposition leaders - ranging from home-based Moslem clergy to westernized politicians - that they have mounted a series of so far unsuccessful missions to Paris to explain to Khomeini the dangers of his radical demands.

But Khomeini's popularity is so great among Iranians, many of whom feel he symbolizes their sense of outrage with the shah, that a prominent opposition leader confided recently: "None of us dare disagree with him in public. It would be political suicide."

They are especially worried by his denunciation of Promised elections in June and any compromise solution as well as a statement last week openly rejecting their advice and calling for a war of attrition against the shah.

Most disturibing for many observers is that both the shah and Khomeini in their own ways seem incapable of understanding the enormous transformations wrought in the 15 years since the religious leader was banished.

In Khomeini's case, the failing is the age-old affliction of exiles imagining an idealized and unchanged homeland, not an Iran in transition where young girls wear jeans and T-shirts and dance all night.

The shah's failing is that of a latter day Ataturk, that of the reformer who has brought about great change but is emotionally incapable of allowing most Iranians to participate in public affairs.

The shah, 58, alternates between carrot and stick. In an often confusing switch of signals, he is variously reported depressed and disillusioned if no longer shocked by the lese-majeste of his unruly subjects.

Thus he releses political prisoners but is accused of turning his troops loose on dissidents in the provinces. In the name of the U.S.-blessed liberalization process he was recently allowed the press limited freedom, tolerates unfettered televised criticism in a supposedly boolticking parliament and promises free elections next June.

Other gestures abound: investigations and arrests of the once high and mighty on corruption charges, including the former head of the dreaded secret police SAVAK; cancellation of the evant garde Shiraz arts festival judged licentious by the religious; cutbacks of outsized purchases of military hardware, nuclear power plants and other advanced technology.

But all this has been to no real avail so far.

For with strikes and demonstrations stretching the fabric of Iranian society close to breaking point, fundamental doubt is the mood of even many pro-shah Iranians.

Constitutional monarchy increasingly appears to be the only solution to many moderate Iranians, but they fear that the shah is not prepared psychologically to abandon the autocratic habits of 37 years of power.

Many are still mindful of the shah's remark in the early 1960s: "When Iranians behave like Swedes, I shall behave like the king of Sweden."

A former minister recalled the shah was once fond of saying that he could not rule as he had 25 years ago and that his son, Crown Prince Reza, 19, now undergoing U.S. Air Force training in Texas, could not rule in the future as he did now.

But the question is whether the changes will come quickly enough.

An opposition lawyer asked: "How long will the people put up with no schools or universities for their children, no work, killings when the leader of the agitation is not here and we are faced with machine guns in the street?"

"Such turnoil not even optimists claim the government has turned the corner. But for the first time in months a mildly optimistic outline of the next few months appears arguable.

The shah has decided to stick with Prime Minister Jaafar Sharif Emami, an old-time court retainer who has surprised friend and foe alike.

By tolerating free debate in parliament - and often mastering it - the prime minister has proven his skill in adopting new style Iranian decmoracy. His image was burnished when he won a battle for moderate press freedom against Gen. Ghomal Ali Oveissi, the martial law boss, who tried briefly to censor the press.

More important was the avoidance of large-scale bloodshed last week on the 40th day after the massacre in Tehran's Jalenh Square which had marked the government's lowest ebb.

Yet even the release of 1,126 political prisoners this week to mark the shah's 59th birthday has failed to stem the growing tide of demonstrations, especially outside the 12 major cities subject to martial law since September.

Nor has the government succeeded in reopening schools and universities. University students and professors are demanding release of their imprisoned colleagues, reinstatement of staff summarily dismissed in the past and the removal of security guards from the campus.

The optimists hope that martial law could be lifted well before the March expiration date and thus allow the maximum time for political groups to organize and contest parliamentary elections in June.

But despite the probably presence of international observers and foreign press such is the suspicion aroused by the shah that many Iranians doubt that free elections are possible.

Right now the shah is under pressure to do something fast - and the most favored path is the possibility of exposing and punishing high officials, including perhaps even members of the imperial family and court, who have long angered many Iranians with their arrogant corruption.

"If they really open up and go all the way," remarked a Western diplomat, "it could make Watergate look like a simple joke."

For the government could well be unable to stop such public vengeance from mushrooming and the fallout could bespatter the West always an easy target to blame for having led influential Iranians, astray.