Israeli Attorney General Yitzhak Zamir stood alone last week fighting both the prime minister and the Israeli Cabinet in the name of law, order and democratic values.

Zamir was attacked -- and labeled everything from square-minded to unpatriotic -- because he insisted on investigating the role of the super-secret Israeli security service known as Shin Bet in the killing of two Palestinian terrorists who were taken prisoner in 1984. It would be hard to imagine a less popular cause in Israel.

Zamir appeared to lose his battle and was fired last week. But conversations with Cabinet ministers, military officials and Israeli journalists make clear that the Shin Bet security scandal isn't over yet. Like the Lavon affair of the 1950s, it is likely to provoke a continuing political and moral crisis for Israel -- one that could challenge the current Israeli government and determine the balance struck in Israel between security and the rule of law.

What Zamir has said is that the rule of law must predominate, no matter how serious Israel's terrorism problems may be.

The Israeli public appears to have little sympathy for Zamir and his insistence on proper legal procedures. According to one poll, at least 70 percent of the public stood squarely behind Prime Minister Shimon Peres and against Zamir. Facing a choice between security and the law, they chose security. They couldn't understand why an attorney general would want to investigate the head of the Shin Bet, Avraham Shalom, for his alleged role in the deaths of the two captured Arab hijackers and for the cover-up he allegedly arranged later to hide the truth from two commissions of inquiry.

Israelis feel an understandable loyalty and gratitude to the Shin Bet for allowing them to sleep safely at night, work by day, and travel without fear by air.

Zamir believed, however, that the public would come to understand that the Shin Bet case was more than a matter of killing two captured terrorists, but a question of whether the secret services could take the law into their own hands. As one of Israel's most famous intelligence officers put it: "If they are allowed to do this, tomorrow they'll take your son and do the same. You don't give these authorities excess power."

Moreover, if the charges were true and Shalom had ordered the killing of the captured hijackers, he had broken not only the law but also the Israeli Defense Forces' code against killing prisoners. If a new precedent were established that prisoners would be killed, future hijackers would resist to the bitter end rather than surrender.

Zamir believed that as the guardian of law and civil liberties in a country that lacked a constitution, he had a duty to fulfill, no matter how unpopular it might be. Several years ago, against similar political and popular pressure, he had prosecuted Jewish settlers on the West Bank for plotting terrorist attacks against Palestinians.

The Shin Bet scandal landed in Zamir's lap last February, when several of his assistants told him they had received new evidence about the fate of the two Arabs who had hijacked a bus going from Tel Aviv to Ashkelon in 1984 and had later died during interrogation. The evidence included testimony from three Shin Bet members who claimed that their boss had ordered the killings of the two Arabs and then arranged a cover-up.

Zamir had no idea when he began that the scandal might involve two prime ministers: Yitzhak Shamir, who held the post in 1984, when the two hijackers were killed; and Peres, who was prime minister during much of the alleged cover-up.

Soon after he began his investigation, Zamir learned that the three Shin Bet members had already presented their case to Prime Minister Peres. Peres had dismissed the three, convinced that they just wanted Shalom's job, and they were fired from the service.

But Zamir disagreed with Peres' assessment. He concluded that the three Shin Bet agents were men of good character and, after reviewing the facts, he decided it was his duty to go to the prime minister and inform him there was sufficient, reliable evidence to bring a case against Shalom. If the allegations were correct, he told Peres, then Shalom had broken the law.

Zamir ran into a stone wall. Peres told him that he had checked the story and decided not to reopen an investigation. He advised Zamir to close the file. To reopen the case would, he said, damage Israel's security.

The political dimension of the scandal -- the possibility that it might involve some of the highest officials in Israel -- gradually became clear to Zamir. He came to suspect that Shalom might have been acting on orders from the political level, since Shin Bet reports directly to the prime minister -- who at that time was Shamir.

Ezer Weizman, a member of the Cabinet, explains the likelihood that there was political involvement: "No military action, whether an ordinary army type of operation or a covert action, is undertaken in Israel without the consent and approval of the civil authorities -- the defense minister and the prime minister. Therefore, I assume if the allegations are true that Shalom ordered the killing of the two Arab terrorists and the subsequent cover-up the actions must have been approved by the authorities responsible. The man responsible was Mr. Shamir. So I point my finger at the then-prime minister, and I want him to say if he was responsible or not."

(Shamir's spokesman, Avi Pazner, responds: "As prime minister, Shamir gave his full backing to the head of the secret services. He knew what a prime minister should know and acted accordingly.")

The pressure on Zamir to drop the case became intense. According to Israeli sources, Peres formed a troika -- consisting of himself, Defense Minister Yitzhak Rabin, and Vice Premier Shamir -- to deal secretly with Zamir on the Shalom affair, without the knowledge of the rest of the Cabinet. The three men tried without success to get Zamir to abandon the case.

Zamir suggested a compromise. Recognizing the sensitivity of the investigation, he offered to drop the case if Shalom would resign. But Peres refused the offer.

When it became obvious that the long negotiations had reached a stalemate, Zamir decided to take the matter to the police for an investigation. He believed that Israel's long-term security lay in making sure that the Shin Bet was free from corruption and that it abided by the law.

Zamir's foes countered that it is impossible to fight terrorism effectively within the framework of the law.

"When you fight terror, there are many situations that cannot fit under the laws of democracy," says one veteran intelligence officer. "You must break the normal rules of democracy when you fight merciless terrorists who come to kill civilians."

Israel had never seen a confrontation quite like this, according to Uriel Reichman, dean of Tel Aviv Law School: "It's a constitutional drama. Never before was the attorney general isolated, fighting the government."

Zamir knew that in theory he could be dismissed by the Cabinet, and he had announced a few months earlier that he intended to resign. But he doubted that Peres would allow him to be fired. He was wrong. Last Sunday, at the weekly government meeting, he was informed that he was being replaced and that a successor, Yosef Harish, had been found.

But the firing of Zamir may be only a pyrhic victory for Peres and the Cabinet. Reichman predicts that, should the new attorney general try to sweep the affair under the rug, he will spark off a government crisis that could trigger Cabinet resignations and incite a public outcry.

If an investigation occurs, Zamir will have won by forcing the government, however reluctantly, to live by the law. And if the investigation establishes the truth, however unpleasant, Israel also will be the winner -- for it will have proved that, despite living in a near-constant state of siege, it has a viable democracy. Even now, with the issue far from settled, government efforts at censorship haven't stopped the Israeli press from reporting the story. And that, in itself, is a kind of triumph.

As for Prime Minister Peres, perhaps he should remember the lesson of his mentor, David Ben-Gurion, who insisted that every detail of the disastrous Lavon affair be brought to light, even at the expense of abandoning the party he created and going into the political desert with Shimon Peres to form the Rafi Party -- when his party refused to go along with him.

Like Ben-Gurion, Zamir is correct in claiming that security cannot be based on lies.