An Egyptian court today sentenced 107 Islamic extremists to prison terms ranging from two to 25 years of hard labor for their part in a dramatic armed uprising in Egypt at the time of President Anwar Sadat's assassination three years ago.

A special three-man security court acquitted 174 others in a trial that lasted 22 months and involved 302 Islamic fundamentalists. It was the largest trial of Moslem extremists anywhere in the Middle East since the resurgence of fundamentalism a decade ago.

Two of the defendants died during the trial and 19 others remain at large and were not formally tried.

The sentencing, regarded as extremely lenient given the nature of the charges, brought to a close a painful chapter in the contemporary history of Egypt. The period was marked by the Oct. 6, 1981, murder of Sadat and by prolonged strife between the government and Moslem fundamentalists over the country's policies at home and abroad.

For the past three years, President Hosni Mubarak has been seeking to mend deep wounds opened in Egyptian society by the assassination. The relatively mild sentences passed down by the court today seemed in keeping with those efforts.

The court's leniency came as a surprise in light of the severity of the charges, which included attempting to overthrow the government and to establish an Iranian-style Islamic republic.

In Egypt, both charges are punishable by death. The state prosecutor in fact asked for death sentences for 57 of the defendants.

Even relatives of the accused apparently expected some death sentences. Some wore T-shirts with the words "Martyrs of the Islamic Society" written on them. Others carried banners with slogans such as "We'll Avenge Your Blood."

When the sentences were announced by the judge, the accused, crammed into five iron-bar cages, began shouting in disbelief and joy "Allahu Akbar, Allahu Akbar" (God is Great).

The alleged mastermind of the conspiracy, Col. Aboud Zomor, was one of 16 sentenced to what is called here "life imprisonment." It actually amounts to 25 years -- the maximum sentence in the Egyptian legal system.

Zomor was sentenced on an additional charge to another prison term of 15 years with hard labor. It was unclear if this second term would be served concurrently or consecutively with the first.

The alleged spiritual leader of the group -- the blind sheik Omar Abdel Rahman -- was among those acquitted. The acquittal announcement was greeted by wild acclamation of the defendant and relatives. The trial was held in an exhibition hall at the international fairgrounds in Nasr City -- an upper-class suburb of Cairo.

Many of the defendants were involved in a raid on the main police station in Asyut, 240 miles south of Cairo. An all-day running battle with security forces was fought there. Eighty-seven persons, most of them policemen, were killed and 156 others were injured.

Both Egyptian and western observers here today were as astounded by the mild sentences handed out as were the relatives.

In April 1982, five members of the same fundamentalist group, El Jihad (Holy War), were sentenced to death and promptly executed for their participation in Sadat's assassination at a military parade marking the anniversary of the 1973 Arab-Israeli war.

The group here known as El Jihad is not believed to have any connection to the Iranian-backed organization called "Islamic Jihad," which has claimed responsibility for the bombings of the U.S. Embassy in Beirut and a number of other recent terrorist incidents in the Middle East. El Jihad is only a fraction of a larger grouping of Islamic fundamentalists here called the Jamaat Islamiya, or Islamic Society.

Some observers felt that since the chief judge, Abdel Kader Ahmed Ali, is about to retire, he acted on his own in determining the sentences, uninhibited by possible political pressure -- direct or indirect -- from the government or relatives of the accused. The length of the trial seemed to suggest that Ali had gone to great lengths to let passions over Sadat's murder subside and to allow the defense to argue its case fully.

Other observers, however, felt that Mubarak, anxious to heal his nation's wounds and appease Islamic fundamentalists, urged clemency.

Egyptian courts are normally quite independent but have been known to yield in the past to direct government pressure in cases with major political ramifications. This was particularly common during the Sadat era.

The Mubarak government, in its dealings with the Moslem right, has taken a tough stand with anyone even vaguely suspected of plotting subversive activities. But it also has sought to reintegrate as many as possible of these Egyptians into the mainstream of political life.

Thus, Mubarak allowed the Moslem fundamentalists to run in last May's parliamentary elections as members of the New Wafd Party. At least 14 of them won seats.

In addition, Mubarak has gone to great lengths to avoid doing the things Sadat did to provoke the fundamentalists. The former president closed down sidewalk mosques, derided the conservative dress of fundamentalist women and gave prominent display in the press to his wife.

Mubarak has created an atmosphere of greater tolerance for legal activities by the Islamic right while still keeping a close eye on potential extremists.

Another delicate legacy of the same period -- Sadat's disestablishment of the orthodox Coptic patriarch, Pope Shenouda III, and his banishment to a monastery in Wadi Latrun -- may also be in the process of being resolved.

While the pope still lives in isolation, Mubarak has allowed him to resume some of his activities. There is speculation that he may be reinstated soon.