The Egyptian government said today that 18 Army officers had been dismissed because of "their fanatic religious tendencies" and declared that agitators provoking civil disorder in the future would be shot on sight.

The twin announcements were believed to signal the beginning of a major probe and purge of Moslem fundamentalists both in and outside Egypt's military establishment following the assassination of president Anwar Sadat by religious militants led by an Army officer.

Government officials, who said the ousted officers had been transferred to civilian jobs, were also reported to be questioning eight other Army officers about the security breaches that allowed Sadat's assailants to bring grenades and ammunition to the military parade where they killed him last Tuesday.

The revelation of the government's continuing concern over fundamentalist penetration of the military came as Lt. Gen. Abdel Halim Abu Ghazala, the Egyptian defense minister, admitted that Lt. Khaled Ahmed Shawki Islambouly, the alleged mastermind of Sadat's assassination, had previously been investigated, then cleared by the military on charges of being a Moslem extremist.

"The civilian state security service had sent a report to the defense ministry about Islambouly's religious inclination," Ghazala was quoted as saying in an interview in Mayo, the weekly newspaper of Sadat's ruling National Democratic Party. "Military intelligence officers watched him but found no evidence of disloyalty. He was well behaved, never absent from duty and was known for his loyalty and discipline."

The general's interview, which also shed new light on the killing of Sadat, appeared on the eve of a national referendum that was expected to confirm Vice President Hosni Mubarak as Sadat's successor. Mubarak is the only candidate.

Although there were no reports of unrest in Cairo as the referendum approached, an Interior Ministry statement warned that "instructions were issued to all policemen to open fire immediately on anyone who attempts to disturb the security of the people and the state." The announcement formed part of a report on last Thursday's daylong clashes between Islamic militants and police in the town of Asyut.

The report put the official death count in last week's hostilities at 53, including 44 policeman and nine Moslem fundamentalists, and said 98 policemen were wounded and 27 fundamentalists arrested.

Ghazala, in his interview, revealed for the first time that all four of Sadat's assassins were still alive, despite previous government accounts that one of them had been killed in the shootout that followed the assassination.

Ghazala confirmed previous government accounts that listed Islambouly as the plot leader and said that the others in the plot were a former Army officer sacked for his "extremist tendencies," an Army reservist who had terminated his service, and a former Army corporal. Aside from Islambouly, none of the others implicated have been named.

"The confessions of the culprits show they are religious extremists and that they committed the crime on their own, and that they have no connection with any other groups," Ghazala said.

Previously, the government had indicated the group members were Moslem fundamentalists and that Islambouly's brother, a member of an Islamic secret society called Takfir wa Hijra (Repentance and Flight From Sin), had been arrested last September in a crackdown against dissidents ordered by Sadat.

Ghazala's interview in Mayo was accompanied by the first photograph of Islambouly to be published. It showed a burly, muscular man on a hospital bed, with a full face and a black mustache. Ghazala said the lieutenant had been in a coma since the killing and had not been interrogated, though later reports today indicated that Islambouly had recovered consciousness and was talking to investigators.

The Egyptian defense minister said the president's killers had apparently had no trouble getting the arms and ammunition they needed. He revealed that 100,000 rifles had been distributed to the general population in 1956, at the time of the war with Israel and the occupation of the Suez Canal by British and French forces. Other weapons, he said, could easily be smuggled into Egypt across the western desert that links the country to Col. Muammar Qaddafi's Libya.

The ammunition, according to the interrogation of the alleged killers, had been purchased in the Upper Nile town of Deshna, 325 miles south of here. One hundred rounds of ammunition had been bought by the conspirators at 15 piasters (12 U.S. cents) a cartridge, and the four grenades used had cost 23 piasters (26 U.S. cents) apiece.

Ghazala further indicated that Islambouly and his cohorts had previously decided to kill Sadat at the first opportunity. When Islambouly was assigned to lead his gun crew in the Oct. 6 military parade that was to honor the start of Egypt's 1973 war with Israel, the decision was made to act at that moment.

The artillery lieutenant sent three of his eight-man squad off on leave and his accomplices, dressed in Army uniforms, bypassed the heavy security at the parade grounds by stating that they came from a separate division, but had been assigned to participate in the parade to fill the ranks of Lt. "Khaled's" gun crew.

The lieutenant dressed down the imposters in public for being late in a scene apparently calculated to dispel suspicion.

According to the Egyptian defense minister, the original plan called for Islambouly to drive the military truck in the parade until it reached the presidential reviewing stand, where he was to turn the truck and drive it straight at Sadat while his colleagues opened fire.

That plan was discarded because of fears that the lieutenant's appropriation of the driver's seat would look suspicious. Instead, when the assassination squad reached the reviewing stand, the lieutenant forced the driver, since declared innocent of participation in the plot, to stop so the four men could charge Sadat on foot.

Ghazala said he remembered looking down after watching an Air Force squadron fly over just in time to hear the jet-muffled sound of gunfire and see a grenade pass through the air overhead and explode behind him. A second grenade landed in front of Sadat and exploded, the general said, then "I saw him Islambouly aiming a short, Swedish-made Karl Gustav machine gun directly at Sadat and those behind him."

Meanwhile, in neighboring Libya, the former Egyptian chief of staff, Saadeddin Shazli, sacked by Sadat at the height of the 1973 war with Israel in a dispute over strategy, and since then the self-proclaimed leader of the exiled Egyptian Liberation Front, warned Egypt that more trouble and violence was ahead.

In a news conference in Tripoli, Shazli praised Sadat's killers and said that though some said theirs was an act of terrorism, he considered it "an act of patriotism . . . those courageous men pulled the trigger in the name of God."