President Carter and the shah of Iran ushered in the new year of 1978 together at a lavish party in the splendid Niavaran palace in Tehran.

Carter danced with the shah's wife, Queen Farah, and the shah's twin sister, Princess Ashraf.Later he conferred with King Hussein of Jordan, whom the shah had thoughtfully invited to discuss the U.S. negotiations for a Middle East peace.

"Iran," the president began his toast, "because of the great leadership of the shah, is an island of stability in one of the more troubled areas of the world."

For some reason, Carter put aside the "cool but correct" remarks that had been suggested by Ambassador William Sullivan and delivered a glowing, highly personal toast. He referred to the shah as a man of wisdom who was loved by his people.

"There is no leader with whom I have a deeper sense of personal gratitude and personal friendship," Carter said. Sullivan later described the presidential toast as "far out."

If Carter was more effusive than Sullivan might have wanted, who could blame him? The shah only weeks earlier had made good a pledge to stall an oil price rise by the Organization of Petroleum Exporting Countries and he seemed to be more cooperative on the question of limiting the weaponry the United States would sell to Iran.

The evening was, no doubt, one of great moment for Carter, still in office less than a year. For the shah, he was now dealing with his eighth U.S. president.

It was the second and last time they were to see each other.

Within a week, the shah was enmeshed in a chain of domestic unrest that was eventually to bring him down. On Jan. 7 in Tehran, an article presumed by the U.S. Embassy to have been prepared secretly by the shah's government appeared in one of the city's two major dailies. It attacked an exiled mullah, Ayatollah Ruhollah Khomeini, a revered religious leader living in exile in Iraq. The article said that 15 years earlier Khomeini had led, on behalf of landlords and communists, a series of massive, antigovernment protests against land reform and the enfranchisement of women.

But, in fact, the protests were not over reform at all but over government decisions to allow the U.S. military -- a growing presence in 1963 -- to have immunity rather than be subject to local law. Khomeini said such statutes were illegal under Islamic law and were the shah's "capitulations" to foreign domination.

The 1963 protests led by Khomeini eventually resulted in riots and bloodshed. First, Khomeini was arrested. Unrest continued and later in the year the ayatollah was exiled to Iraq. But, before he was gone, the shah's troops had invaded his theological college in Qom and killed one cleric. As violence continued, the shah finally unleashed the military against the clerics and there were thousands of deaths.

Fifteen years later, the resentments were still strongly felt in the community of Shiite Moslems who followed the exiled Khomeini. So when the anti-Khomeini article appeared on Jan. 7, 1978, there was an immediate reaction. A crowd estimated at 5,000 gathered at a Moslem shrine in Qom to protest both the article and the imprisonment of another ayatollah, Seyed Mahmud Talaghani, who had been jailed the previous summer.

When the crowd emerged from the mosque, the shah's troops fired on it, killing 20 people or more. Whether the decision to fire was the shah's or the act of a rash commander or frightened troops is still open to question. But the shots fired then gave focus to the popular discontents that became in time an unstoppable groundswell of revolution. Turmoil Begins

The Morning Summary produced by the State Department on Jan. 14 noted "a growing restiveness in Iran over the past several months" and attributed it to the same economic sources of dissatisfaction noted the previous fall by an analyst in the State Department -- and rejected by the State Department hierarchy.

The Morning Summary returned to the same subject 15 days later, reported that the shah's Islamic opponents were in their strongest position since 1963, and described the policy dilemma that the shah faced as he chose between control and liberalization of the society. Like many items touched on once or twice in the Morning Summary and not regularly repeated, it passed virtually unnoticed.

In accord with Moslem tradition, Shiite groups gathered across the country every 40 days to mourn those who died at the mosque in Qom. In February, at the first such mourning, troops again fired into the crowd, this time in Tabriz, in the province of Azerbaiijan near the Soviet border. More than 100 people were killed.

From then on, relentlessly and predictably, every 40 days ever larger gatherings of mourners demonstrated in provincial cities, always to be met by military resistance, confrontation that often ended in riots and bloodshed.

In Tabriz, in the first government response to official violence, the shah fired the local chief of SAVAK, his secret police. He gave every impression of being intent on riding out the protests, maintaining that they were led by a small group of religious fanatics with the occasional support of communist opportunists. A coalition of "the red and the black," the shah called it.

As the protests spread, however, the young U.S. consul in Tabriz, Michael Metrinko, who is now a hostage, began to sense that something was taking place. Metrinko spoke Farsi, the native tongue, as well as Turkish, and, as the only American official in Iran's fourth largest city, he was in touch with many elements of Iranian society whom U.S. diplomats rarely knew -- merchants, students, workers and the clergy.

From February on, Metrinko's reports were in sharp contrast to those of his colleagues in Tehran. Where embassy officials saw the small circle of "red and black" malcontents that the shah spoke of, Metrinko perceived an ingrained hatred of the shah spreading throughout the society.

The mosques, Metrinko wrote, provided the foot soldiers of protest, but the merchants of the bazaar, a bourgeois power group in Iran, were now financing opposition to the shah and working with the mullahs.

These "bazaari," as they were called, were still smarting from an anticorruption campaign initiated against them in 1976 by the shah. Their discontent meant to Metrinko that dislike for the shah was much more resonant than anyone in Tehran seemed to recognize.

In addition, Metrinko reported that many Iranians with ties to the shah were secretly removing their money and valuables from the country. His detailed findings did not agree with what the embassy in Tehran was reporting. dMetrinko's memos were regularly held up when Ambassador Sullivan suggested that he talk to a broader spectrum of Iranians, including supporters of the shah, and prepare a more coherent overview. These longer reports were generally sent as "airgrams," a lower priority message with less likelihood than a cable to be read at the top levels of State. Metrinko, according to former associates, saw this as a gambit to stall and dilute his dissenting views.

Thus began a pattern that was to be repeated through the final four or five months of the shah's reign: One U.S. agency or an arm of it would paint a rosy picture of the shah's future, only to be contradicted by another agency or an arm of the same agency. Occasionally the same analyst would conclude that the shah was done for, and then, a while later, reverse himself and maintain that the shah's future was secure.

At the same time, back in Washington, several American academics were spreading similar reports to intelligence analysts in the State Department. The shah, they said, was in deep trouble. He was losing the support of traditional followers. George Griffin, an intelligence analyst, was disturbed enough to organize a meeting of middle-level staff to review the warnings, but few high-level staff even attended. James Bill, a political scientist from the University of Texas, told them bluntly: "Time is not on the side of the shah of Iran."

"The government can now only respond with more and more coercive force and military control and repression," Bill said. "The large groups of individuals already alienated by the regime will in turn become more demanding and desperate in their response. And they will be joined by others -- the only common denominator to their cooperation being opposition to the regime. As this occurs, the shah will have lost the will and capacity to use his traditional tactics of political control. Unless something is done again to break this wildly spinning vicious circle, the future of the current actors in the Iranian political drama can only be a grim one. And the American future in Iran can in no way be considered bright." Reports on SAVAK

The embassy in Tehran saw no such portents. The shah was entrenched and could brook all rebelliousness. Besides, support for the shah had become a matter of institutional theology after the president's decision the previous fall to continue the close relationship. Sullivan did pass on to Washington new reports of harsh activities by SAVAK.

SAVAK had been responsible for bombing the homes of lawyers and teachers identified with nonviolent political opposition. Well-known dissidents were being beaten by gangs called the "Underground Committee for Vengeance" and the "Resistance Corps," both believed to be arms of SAVAK or the police and operating with the explicit approval of the shah. The government had "exiled" several religious leaders by prohibiting them any contact with their followers and forcing them to live in other parts of the country.

Sullivan, a 30-year veteran of the Foreign Service, with experience at some extremely difficult assignments, felt strongly that it was naive for the State Department to push the shah on human rights violations, and his reporting left little doubt as to the conclusions the embassy had drawn. The shah was attempting to liberalize the society, but he could not afford to lose control over the process.Dissident groups were referred to as "students and other miscreants;" freedom of expression was said to be an "aspect" of "permissiveness."

While Sullivan was sending home cables that spoke of the shah as firmly in power, the ambassador realized that his knowledge of the political opposition was sharply limited. Since the 1960s, when the shah expressed irritation at a young political officer at the embassy (William Miller, now staff director of the Senate Intelligence Committee) who helped an opposition group draw up its internal constitution and later at CIA contacts with political dissidents, most U.S. intelligence information in Iran came through SAVAK. Sullivan made various efforts to overcome this handicap, but without much success. The ambassador knew that, despite its reputation for ruthless efficiency, SAVAK, like many secret police organizations, was not considered very effective.

SAVAK, for instance, referred to all "leftist" groups as "communists," particularly if any of their membership had Palestine Liberation Organization or Libyan training; SAVAK constantly confused the two principal terrorist organizations in Iran, "the People's Sacrifice Guerrillas" and "the People's Strugglers," with the Tudeh party, which had not advocated violence against the government as had its Maoist offshoot, but SAVAK seemed unable to distinguish between the two.

Moreover, "for years, SAVAK has maintained that the communists have no centralized structure and that it is led by men of low caliber, but it concedes that the party has as many as 1,000 members active in areas such as Tehran, Tabriz, Azerbaiijan, Abadan, Shiraz, and Esfahan," the CIA concluded in a top secret memo. But the CIA was not "confident that SAVAK has the capability to penetrate or determine communist underground. Over the past few years, SAVAK has managed to round up only a very few 'party members.'"

Unfortunately, SAVAK's diagnostic difficulties did not end with communists. They also seemed unable to distinguish between the various types of noncommunist opposition groups, frequently confusing them with "communist groups" and always confusing them with each other.

SAVAK could never infiltrate subversive groups, was unsophisticated at analysis and its information gathering was largely limited to what could be obtained through torture.

So Sullivan, acting on his own, instructed his political officers at the embassy in Tehran and CIA station personnel to expand their activities and to pick up direct intelligence from both the religious and more moderate opposition elements in Iran. The embassy staff felt, in any case, that however spotty their information was, it was still much better than the intelligence estimates from Washington, which seemed to them simplistic in the extreme.

On June 1, Sullivan forwarded a report on "the internal scene" in Iran. Drafted by the embassy's political counselor, George Lambrakis, the report was two weeks in the preparation and it rambled over 11 single-spaced pages.

Overall, its thrust was one of optimism for the shah. "The embassy soundings among religious leaders," the report said, "suggest an underlying basis of loyalty to the monarchy and to the independence of Iran as the shah envisions it, but increasing unhappiness with the breakdown of communication from the religious leadership to the shah."

These conservative religious leaders, the report said, "view themselves as the backbone of the opposition to the spread of communism in Iran."

Despite that conclusion, the paper focused on what had become a growing uncertainty among the populace, and expressed concern for the future.

The shah had gradually ordered "considerable relaxation of press censorship, a tolerance of political criticism and of minor manifestations of dissent, and a more genteel system of police controls. . . .

"The shah has staked his prestige on a degree of permissiveness and civil rights and freedom of expression which has drawn oppositionists into the open, but he has displayed a measure of uncertainty in indicating how he intends to deal with them.

"It is obvious," the report went on, that the shah is "having trouble keeping Pandora's box partly open. His original experience in encouraging freedom of expression led to vitriolic attacks on the government and built expectations of more serious internal reform than what he perhaps had in mind when he started."

Sullivan's cable confirmed the reports of extensive violence against dissidents and blamed the shah's government for setting off "a brush fire of religious opposition" that "rehabilitated Khomeini in the eyes of religious leaders."

For the first time, the embassy in Iran reported that economic problems were causing chaos -- a view that the State Department had rejected in 1977.

Affluence resulting from the 1973-74 quadrupling of the price of oil had led to double-digit inflation, caused mass migration from the countryside to the cities, served to break up the traditional Islamic family and cultural patterns of the society, and had raised expectations throughout the populace. Furthermore, widespread corruption in high places was universally recognized and despised. While such corruption "unfortunately permeates the traditional Iranian social system," it nevertheless made many in the society "cynical," according to the report.

In a piece of analysis that reflected the shah's views, Sullivan noted that by providing broad access to education in an attempt to build a "prosperous middle class" that would support him and his dynasty, the shah instead had created a growing cadre of critics without any political voice in the society.

The shah had failed, the report said, "to provide clear operational guidelines for his administrators and security people in dealing with dissenters . . . The shah's new directives to his security forces, such as instructions to desist from torture . . . are disorienting."

"Those in charge of security are being told that they will be held responsible for any major new outbreaks, but are also being prevented from using the time-honored methods of arrest, long imprisonment and manhandling -- if not worse -- to get at the threat."

"The [recent] rioting . . . which elicited the government's announcement of a crackdown of street demonstrations was the first of a possible series of steps backing away from liberalization. . . ."

"The Chinese experience of letting a thousand flowers bloom and then chopping them down, would be pertinent," the memo noted.

"The violent and the nonviolent, Khomeini extremists and small groups of terrorist guerrillas, all represent diverse interests which would not combine against the government if the government were clever in keeping them divided." The shah had succeeded in wiping out "left-wing elements" in the past with the support of conservative segments of the society.

The shah was at a crossroads, the report said. Sullivan assumed that the shah would not give up real power. He "will not permit events to escalate to the point where national security, as he sees it, will be threatened."

What was needed, in Sullivan's view, was for the shah to perform adroitly, to keep the opposition divided, "to open better channels to the religious leadership and . . . to act on some of their complaints. If done deftly, this should go a long way to assuage them and lead to a breakdown of opposition unity."

But Sullivan added a disclaimer: It is, he wrote Washington, "too early . . . to be definitive on the direction the shah will take." Divided Views

It was not long before the shah learned that Sullivan's staff was in contact with the opposition. He took it up with Sullivan, asking whether such meetings were a sign of waning support for him by the United States.

The shah explained to Sullivan that he had recently been assured in a telephone call from Nelson Rockefeller that the United States was behind him and to expect a call from the White House confirming that. Shortly afterward, the shah said, the president's national security adviser, Zbigniew Brzezinski, telephoned.

What was American policy, the shah asked Sullivan.The ambassador assured him that he still had U.S. support.But the message from the shah was clear -- any American contact with opposition groups would be interpreted as a shift in loyalty.

In July, Sullivan, back in Washington on home leave, took up the matter with David Newsom, the undersecretary of state for political affairs, the day-to-day chief of all ambassadors for crisis situations. Newsom is said to have agreed with Sullivan that the contacts were valuable and should be continued, regardless of the shah's objections.

By midsummer, the seeds of concern about the shah's future were flourishing at the State Department, but had hardly been noticed, if at all, by the chief policymakers. Instead, the discussions about Iran had to do almost exclusively with arms sales to the shah.

Two young analysts who were more skeptical, human rights deputy assistant secretary Stephen B. Cohen and Theodore Moran, who had written an earlier report suggesting the shah was in deep trouble, now had a new idea -- a zero-based analysis of the U.S.-Iranian relationship. They would accept the shah as a fact of life but proposed to start from scratch and analyze every aspect of the relationship. For example, instead of giving the shah additional planes to protect his air force from being wiped out in an attack, why not give him reinforced, attack-proof hangars? Moran's boss, Anthony Lake, head of policy planning, approved the project. Before the two could get very far, they were told by Lake to stop.

The same split in views that prevails now, three months after the shah's death, prevailed then. For many American leaders, the shah was a longstanding ally of the United States; if not a puppet, then at least a willing and most helpful partner in maintaining crucial American interests. On the other hand, he was seen by many others as a corrupt tyrant, an oppressor of his people, a megalomaniac who saw weapons as toys.

The internal debate, was not over whether the shah could survive, but whether the United States, now led by a president who had promised to take the United States out of the arms business, should be supplying him weapons that, in some instances, were difficult for the American military to operate.

On July 5, 1978, Secretary of State Cyrus R. Vance chaired a policy review meeting on Iran at the White House. In attendance were Brzezinski, Secretary of Defense Harold Brown, CIA Director Stansfield Turner and Newsom. The specific subject for what seemed like the 100th time was arms sales but the underlying issue, as Sullivan had complained, was whether the United States should continue such close ties with the shah.

It was not a discussion the participants wanted to hold, and they rapidly came to a decision that cut it short. Arms sales to Iran ought to continue, they agreed, because they contributed to the national security of the United States and the only question was how much.

They were, however, faced with a serious dilemma. The shah had requested $15 billion in equipment over the next five years. But, following a campaign promise, the president had limited U.S. arms sales early in his administration. Effectively, he had said that total arms sales could never exceed what they had been the previous year.

With a $3 billion per year average, the shah's request would cut deeply into the overall allocations of arms sales. In order to keep the grand total under the previous year's total they would have to cut back the arms to be sold to Israel, Taiwan, Korea, Saudi Arabia and possibly Pakistan, Vance's briefing memo for the meeting said. In effect, they would be jeopardizing other highly regarded security commitments.

The administration would find a way to get around the president's ceiling on arms sales, in all probability by persuading the shah to spread out his purchases over a longer period.

That left only one issue that the meeting failed to resolve -- the shah's desire to obtain the F4G, a highly sophisticated aircraft known as the Wild Weasel. The president would have to decide that one himself.

Four days later, Newsom arrived in Tehran to meet with the shah and talk with U.S. Embassy officials. The undersecretary told the shah that the United States appreciated his difficult but successful efforts to "achieve a more open domestic political debate while maintaining public order."

The shah responded with what had become his standard theme. "I want to turn over to my heirs a kingdom that is politically modern as well as technologically modern. I am going to try to undertake such political . . . reforms but I know there is risk in doing so."

Newsom informed the shah of the presidential decision -- no Wild Weasels for Iran, at least for the present.

Afterward, Newsom met with most of the embassy staff at the home of Charles Naas, deputy chief of the mission. The consensus was that the shah's position was secure. Tehran was alive with a different story, a rumor that the shah was dying of cancer.

Recognizing the importance of being in touch with popular sentiment in Iran, the State Department during the summer of 1978 put out a personnel notice seeking to recruit people who spoke Farsi. No one signed up.