Mohammad Reza Phalavi, the deposed shah of Iran who was a strategic ally of the United States for nearly four decades, died in exile today in an Egyptian military hospital.

The deposed shah, 60, years old and drained of strength by lymphatic cancer, succumbed at 9:50 a.m. (3:30 a.m. EDT) to a buildup of fluids in his lungs and shock caused by allnight hemorrhaging from an abscess in his pancreas, a medical bulletin said.

His wife, and four children and several aides, in the hosptial for an all-night vigil, broke down in sobs when death came after a night of steady deterioration, hosptial sources reported.

President Anwar Sadat declared in a televised address that Egypt will hold a state funeral for "my departed friend." Other officials said the former shah would be buried in Rifai Mosque, one of two 19th century Turkish-era monuments near the ancient Citadel of Saladin on the heights of Cairo overlooking the Nile.

The shah's father, Reza Khan, was buried briefly in the same mosque during World War II before the return of his corpse to a shrine in Iran.

The official military funeral is planned for Tuesday, the Egyptian sources said. But other sources cautioned that Sadat, while bestowing a final honor on his friend, would be unlikely to turn the occasion into too grand a ceremony because of possible embarrassment. In the first hours following news of the shah's death, only Sadat himself, Isreal and the United States had any kind words to say about him.

The White House said that there would be no announcement of who would represent the United States, if anyone, until formal funeral arrangements are completed. But former president Richard Nixon announced he would come to Cairo for the service.

It was the end to 18 months of wandering exile during which the shah had become an international pariah unwelcome in countries, including the United States, which once had sought out his friendship and the oil wealth that his royal government spent lavishly to transform Iran into a modern state.

Spokesman for the Islamic revolutionaires who chased the shah from his throne Jan. 16, 1979, said in Tehran that his death would have no effect on relations with the United States or attempts to secure release of American hostages held in Iran since Nov. 4. It was the shah's hospitalization in the United States last fall that led to the seizure of the Americans and Iran's Islamic zealots said then they would be released only if the shah returned to stand trial for his conduct before the revolution.

Sadat, who welcomed the former shah here when no one else would have him last March 24, flew from the seaside resort of Alexandria to Ciaro when he learned of the death, going immediately to console the Pahlavi family at their quarters in Egypt's stately Kubbeh Palace.

Defying criticism from Arabs sympathetic to Iran's Islamic upheaval as well as a small group of Moslem fundamentalists within Egypt, Sadat had based his acceptance of the Shah on the Islamic principles of friendship and hospitality. In this light, most Egyptians have seemed to welcome the gesture. Demonstrations by Islamic zealots against his refuge here never drew much support.

In his address to the nation, Sadat repeated the theme of Islamic hospitality in pledging a state funeral for the shah to "bid him farewell with the same amount of honor and respect as we greated him with here when he arrived."

"I mourn my departed friend before the entire world, especially the Moslem world," he said, and in a gesture again underlining his concern, he called Crown Prince Reza "my son and said the 19-year-old "will now be taking over as the head of the Phalavi family." Sadat offered continued refuge to the shah's wife, Farah Dibah, and the rest of the family.

The shah had grown increasingly resentful about his treatment by his former friends in the months leading to his death. In his last major interview, with The Washington Post on May 23, he said he regretted not using more force to put down the revolution before he fell and he accused the United States and Britain of contributing to his demise.

"Well, now you have it," he said pointedly addressing the U.S. government.

"Are you happy?" Do you have human rights there now? Democracy? Liberalization? What they are doing to my country in the name of Islam just makes people go away from Islam."

The shah was at work rewriting a book on his downfall published eariler this year in French.The revised version was to include a calling into question of the U.S. role in Iran's Islamic revolution and the shah's own fate.

Egypt was the shah's first stop after leaving Iran, but he soon began an odyssey that eventually brought him to the United States and then to Panama before returning here for surgery.

Following an operation to remove his cancerous spleen at the Nile-side Maadi Military Hospital on March 28, the shah was undergoing chemotherapy to retard his six-year-old cancer of the lymphatic system.

Doctors said this weekend the shah and prevented him from gaining weight except during periods when the treatment was stopped to allow him to regain strength. More importantly in the end, it also sapped his resistance to infection, they said.

The shah reentered the hospital for what became the last time on June 27, suffering from a high fever and complaining of chest pains. Doctors found that an earlier round of pneumonia had left a buildup of fluid at the bottom of his left lung. To remove the accumulation, they operated on June 3o, inserting a small tube to drain away the liquid.

In addition, the team of French and Egyptian doctors had discovered a small abscess on his left lung apparently the result of a routine blood test. The infection at the spot where the skin was punctured was being fought with antibiotics.

It was the abscess on the pancreas, also being fought with antibiotics, which led to the bleeding that contributed heavily to death, the Maadi hospital bulletin said. Doctors at the hospital had said earlier that the abscess grew from a tiny cut on the organ, perhaps made at the time of the March 28 spleen removal.

Western experts had said at the time the shah checked into Maadi hospital for the operation that Egyptian facilities were more than adequate for the operation, but that the real weakness in Egyptian medicine lay in post-operative care and the dangers of infection.

The shah's team of doctors here, however, had stressed since the recent series of infections began that they were due mostly to the former monarch's weakened condition and consequent inability to resist.

During his hospitalization, the shah received massive transfusions of his rare B-negative blood to build up his white cell count in an attempt to increase his power to combat the infections, Egyptian doctors said. In addition, the chemotherapy had been stopped and on several occasions spokesman for the shah issued bulletins declaring he was improving and taking walks about the hospital.

A spokesman said today that the shah was "aware and awake up until the last half hour. He knew the end was near."