King Hassan II of Morocco, a sage and worldly Muslim leader who played a peacemaker's role in the Middle East and outfoxed plotters in several coup attempts while ruling his North African realm with an iron fist, died yesterday after entering a Rabat hospital suffering from pneumonia. He was 70.

Hassan, 17th in an Alawite dynasty stretching back 400 years, was the Arab world's longest-ruling monarch, having succeeded his father, Mohammed V, in March 1961. After 38 sometimes tumultuous years on the throne, he left behind a kingdom of 29 million known for stability, sunny hospitality and friendliness to Israel and the West--but also pressured by population growth, unemployment and Islamic activists chafing at his authoritarian government.

The official heir to the throne, Crown Prince Sidi Mohammed, 36, immediately took over for his father, the government announced. Long reputed to be more interested in the high life than government affairs, Sidi Mohammed has been groomed increasingly in recent years for his ascension to the throne and command of the Royal Armed Forces.

"I announce to the Arab and Islamic nations and to the world the death of a great leader and a man of this world's great men," Sidi Mohammed intoned on a national television broadcast within hours of Hassan's demise.

Sidi Mohammed, who described the cause of his father's death as a heart attack, did not refer directly to his own ascension. After his announcement, the kingdom's television switched from regular programming to readings from the Koran, the Muslim holy book in whose melodious precepts the deceased monarch was uncommonly well versed.

One of the first tributes issued on news of Hassan's death came from former Israeli prime minister Shimon Peres, who had been in contact with the Moroccan monarch on numerous--and often secret--occasions in the days when Arabs and Jews rarely spoke to one another in the Middle East.

"He was a visionary, a believer in peace," Peres declared in Jerusalem. "He supported it, dreamed of it and fought for it."

The White House announced that President Clinton had expressed his condolences to Sidi Mohammed by telephone and will attend the funeral. "We look forward to a new relationship with the Crown Prince and keeping the excellent ties between our countries," said Michael Hammer, a National Security Council spokesman. "Our view is the Middle East has lost one of its greatest peacemakers."

Hassan, whose health had been fragile for several years, left a widow, Lalla Latifa, three daughters and another son. He lived a life of contrasts, and often of risk.

Renowned as one of the great practitioners of classical Arabic oratory, he also was fluent in French, English and Spanish. Schooled in the intricacies of the Koran, he held a law degree from the University of Bordeaux and trained aboard French Navy ships. Proud to claim lineage back to the prophet Muhammad, he also had a reputation as a playboy when young and moved as easily on the kingdom's manicured golf courses as in Paris salons--or at home in a series of palaces beautified by lavish Moroccan tile and fountains indoors and out.

The best-known contrast, perhaps, was Hassan's claim to have special responsibility for preserving the Islamic character of Jerusalem--commander of the faithful was one of his titles--while at the same time maintaining discreet relations with Israel and cultivating Morocco's own Jewish inhabitants throughout his reign. President Anwar Sadat's ground-breaking visit to Jerusalem in 1977, for example, followed a series of secret meetings between Egyptian and Israeli officials hosted and encouraged by Hassan.

Shortly after taking over from his father, Hassan took one of the risks he was to become famous for, seeking to end a desert war with Morocco's eastern neighbor, Algeria. He met with Ahmed Ben Bella, then Algeria's president, and unexpectedly conceded a broad swath of disputed desert land, ending the conflict but drawing criticism from his military.

He dispatched 350,000 unarmed Moroccans on a "Green March" to the former Spanish Sahara in 1975 to stake his claim to the desolate territory long considered part of the Alawite domain. The outcome was a long war with the Polisario guerrilla group seeking to form an independent Saharan nation, a dispute now scheduled for settlement through a U.N.-sponsored referendum.

While viewing himself as an old hand in Middle East affairs with advice for U.S. presidents as well as fellow Arabs, Hassan also embarked on foreign adventures that startled and sometimes irritated his friends in Washington, Paris and Jerusalem.

At one point in 1984, he sought to form a union with the erratic Col. Moammar Gadhafi of Libya. More modestly, he joined Libya, Algeria, Tunisia and Mauritania in the Arab Maghreb Union 10 years ago, a grouping designed to become a common market and trading bloc but which never got off the ground.

Because he seemed always to emerge from such difficulties unscathed, Moroccans liked to say Hassan enjoyed a special baraka, or good fortune. Never was that more apparent than in his escapes from a number of attempts to overthrow him, some of them particularly bloody.

About 2,000 soldiers under the command of officers seeking to set up a military regime attacked Hassan's birthday party in 1971 at the seaside Skhirat palace. Firing wildly, they killed nearly 100 guests but missed Hassan, who hid in the men's room.

Moroccan Air Force planes the following year attacked a Boeing 727 carrying King Hassan and his entourage, seeking to shoot down the aircraft and destroy the monarch. As legend has it, Hassan had the pilot radio to the attacking fighters that their strafing had killed the king. Then, back at the airport, he popped out the door and ordered the coup leaders arrested.