The deposed shah of Iran ended three months of Panamanian asylum today and left for Egypt, presumably for an operation to remove his enlarged spleen and take up permanent residence on the invitation of President Anwar Sadat.

Two hours after the shah's sudden departure on a privately chartered DC8 from the Panama City international airport, President Carter's chief of staff, Hamilton Jordan, ended his own three-day visit here and flew back to Washington on a U.S. Air Force jet.

Jordan and other U.S. officials, including presidential counsel Lloyd Cutler, apparently failed to persuade the shah to remain in Panama and be operated on here.

A statement issued by Panama said the U.S. team had sought to convince the former monarch, Mohammad Reza Pahlavi, to abide by the Panamanian plans for the surgery. It then declared:

"In spite of the warnings about the risks involved in the long trip and the possible complications his departure might have for the safety of the North American hostages in Tehran, the internal situation of Egypt and the fragile conditions in the Middle East, Mr. Reza Pahlavi reiterated his decision to make the trip."

There also were strong indications that U.S. and Panamanian officials failed in what may have been a last-minute bluff: using the shah's threat to leave as a spur for the Iranian government to take over custody of the estimated 50 U.S. hostages from militants in Tehran.

Iran is believed to have wanted the shah to remain in Panama during extradition proceedings it has instituted against him.

Monday was the deadline for the Iranian government to turn over to Panama documents supporting its charges against the shah.

French attorney Christian Bourget, along with three Iranian diplomats and attorneys, arrived here over the past few days with 450 pages of evidence on charges of "torture, murder and embezzlement" that they had planned to deliver to the Panamanian Foreign Ministry Monday morning.

Bourget and the Iranians appeared shocked by the shah's departure today, but declined comment until they had discussed the matter with Juan Materno Vasquez, the Panamanian attorney representing Iran here.

Today's events left prospects for early release of the U.S. hostages in as much doubt as at any point during their 140 days of captivity. "Obviously," one U.S. official here said, "this may take the whole situation back several spaces."

They also closed the most recent chapter in the shah's five-country sojourn in exile and in one sense brought it full circle -- back to Egypt, the country where he first sought asylum when he fled Iran in January 1979.

U.S. officials here offered a number of speculative reasons for the shah's departure, beginning with his dislike of isolation on the Panamanian resort island of Contadora.

"He had nobody to talk to but [security] goons and occasional tourists," one U.S. official said. At the same time he added, "to put myself in the shah's shoes, he never really understood why Panama was fooling around" with Iran on the extradition proceedings.

At various times since Iran first requested the shah's extradition 66 days ago, President Aristides Royo and other Panamanian officials have indicated variously that the request would or would not be seriously considered, that the shah was or was not under arrest pending receipt of Iran's evidence, and that he was or was not free to leave Panama if he wanted to.

Panama's equivocation over the issue was understood to be intentional -- an attempt neither to give in to nor offend Iran while buying time for the United States to negotiate release of the hostages. By leaving open the question of whether the shah actually would be extradited, the Panamanians avoided closing the door to Iran's continued demand that the shah be returned there before the hostages could be freed.

But the shah, the U.S. official said sarcastically, "after all, was king of kings. He doesn't understand this kind" of treatment.

The official also said that the shah apparently preferred to live his exile in a Moslem country, where he felt more at home, and that he feared being operated on by Panamanian doctors in a Panamanian hospital.

One of many remaining questions was to what extent the U.S. government tried to prevent the shah's departure, on the basis that his move might complicate the hostages' situation.

Panamanians when asked, consistently affirm that either the U.S. or Panamanian governments could have found the means to prevent the shah's departure.

The tactics used in dealing with the shah, one U.S. official said, "were those of persuasion. That's the way this administration does things."

Asked whether the shah's departure marked the failure of the reported bluff to gain a transfer of custody for the hostages, the official said he had no knowledge of that being the case.

The explanations also add to the confusion surrounding recent developments in Iran, in the United States and here.

Two weeks ago, Dr. Benjamin Kean, the New York physician who had treated the shah during the November U.S. hospital stay that originally led to the seizure of the hostages, visited here to examine the shah. Kean then returned to New York and, through the shah's spokesman Robert Armao, issued a statement saying the shah needed immediate surgery to remove his enlarged and possibly cancerous spleen.

Both U.S. officials and the Panamanian doctors who had been treating the shah since his Dec. 15 arrival here, were puzzled and angered by the statement.

Kean no longer was considered here to be the shah's primary physician. He was considered close to friends of the shah, such as former secretary of state Henry Kissinger and David Rockefeller, who felt the shah should have been given permanent U.S. asylum, and there appeared in any case no reason to make a public statement at that time from New York on the shah's condition.

Several days after the announcement, renowned Houston surgeon Michael DeBakey, who previously had not been involved in the shah's case, flew to Panama with his own medical team to examine the deposed monarch. They also reportedly decided he needed the spleenectomy.

U.S. officials at that point privately indicated that they would not look favorably on a request by the shah that the operation be performed at Gorgas Hospital, a U.S. military complex here.

The Carter administration apparently feared that the shah's admittance to Gorgas, even though it is located on leased Panamanian territory since last year's dismantling of the Panama Canal Zone, would be viewed as a sort of readmission to the United States and would further aggravate the hostage situation.

It was arranged for the shah's admittance to Paitilla Clinic, a private institution run by Panamanian doctors that is viewed as the most modern and sophisticated Panamanian medical installation.

Panamanian doctors and the Panamanian government reportedly were adamant that if the shah were admitted to Paitilla, his operation must be performed by a Panamanian surgeon. The Ministry of Health issued DeBakery a temporary consulting license, but refused to give him permission to operate here. DeBakey then reportedly flew off in a huff. Two days after the shah was admitted to Paitilla, he returned to Contadora.

A statement issued by the clinic said the surgery had been postponed for at least two weeks because the shah had blood and respiratory problems and was not in "optimum" condition.

There appears to have been little disagreement between Panamanian and American doctors that the surgery could be postponed temporarily without further damaging the shah's health. Reports published in the United States, however, intimated that many of the shah's friends felt the administration, by in essence refusing his admittance to a U.S. hospital, was signing his death warrant.

Published reports that Kissinger visited the shah here last week could not be confirmed. On Thursday evening however, Jordan arrived in Panama City with Arnold Raphel, a special assistant to Secretary of State Cyrus Vance, and Dr. Norman Rich, chairman of the department of surgery at the Uniformed Services University of the Health Sciences, a U.S. medical training installation in Bethesda.

Their mission reportedly was to try to iron out difficulties surrounding the shah's operation and quell charges that adequate treatment was not being made available to him.

On their way to Panama, Jordan and the others stopped in Houston, where they consulted with DeBakey.

During conversations with Panamanian strongman Gen. Omar Torrijos here Thursday night and Friday, U.S. officials said, Jordan obtained Torrijos' agreement that Panama would let DeBakey and his team operate on the shah at Paitilla Clinic. Rich also inspected the facilities, spoke with Panamanian doctors and U.S. medical personnel here and reportedly determined that the clinic was adequate.

On Friday, Jordan is known to have requested that Carter send Lloyd Cutler, who had dealt with the shah personally on several occasions, to reassure him.

Cutler arrived on Friday evening and went by helicopter along with Raphel, to Contadora. They returned after a 90-minute conversation with the shah, during which they reportedly were unable to persuade him to accept the Paitilla operation with DeBakey, but felt they had left the door open for compromise.

On Saturday, Cutler again spoke with the shah, and Torrijos flew personally to Contadora for what was described as a "courtesy" visit. By then, sources said, it was clear to U.S. and Panamanian officials that the shah was leaving. Cutler returned to Washington Saturday night.

Bourget and the Iranian officials here to present the extradition evidence apparently had inklings of the shah's possible departure. Bourget reportedly spoke with Torrijos, and there are indications here that he also tried, apparently without success, to speak with Jordan.

U.S. officials insisted that the Monday deadline for Iran's submission of evidence for the extradition request had no direct relation to the shah's departure. Under Panamanian law, once an extradition request is made, the petitioning country has 60 days in which to submit evidence.

After the evidence is submitted, however, the executive has sole discretionary power to make the extradition decision. There is no time limit, and President Royo technically could have spent years looking over the evidence. Royo left yesterday for a week-long trip to Japan.

In addition, Panamanian law prohibits the extradition of anyone to a country where the crime with which he is charged holds the possibility of capital punishment.

Iranian officials said here today that while their government had made no direct promise that the shah would not be executed, they were "aware that we have to meet the legal requirements" that would permit Panama to extradite the shah.

The shah, who made a refueling stop in the Azore Islands on his way to Cairo, left with a reduced entourage that U.S. officials said included his wife, a number of bodyguards and some former Iranian Army officers. His children and others who had been staying at Contadora with him reportedly have left the country over the past several weeks. No U.S. official accompanied him to the airport.

In a news conference on Contadora before leaving, the shah declared:

"Our thanks to Gen. Torrijos and President Aristedes Royo. We will always remember Panama with gratitude."