One of them is nearing 70 now, while the other, at 47, is a generation younger. When one was a leading figure in an underground guerrilla organization in the Middle East, the other was a youth, growing up in poverty in North Africa. The older man is a living link to the past, while the younger one, in the view of many, is riding the wave of the future.

Yitzhak Shamir and David Levy have little in common in their backgrounds, but they find themselves today locked in a struggle for control of their political party, Herut, and the Likud bloc political alignment that Herut leads. It is a three-way contest, for looming over both men is the shadow of former defense minister Ariel Sharon.

Herut and Likud have never fully recovered from the September 1983 resignation of their founder, former prime minister Menachem Begin. Shamir, Begin's colleague in the Jewish underground forces that fought the British in preindependence Palestine, inherited the party leadership and the prime minister's job.

But the Shamir government lasted less than a year, and Shamir had to fight off a serious challenge to his party leadership by Sharon. Now these three men serve as ministers in a government headed by Shimon Peres of the Labor Party, while each waits for the moment he can bid to lead the Likud against Labor in the next election.

Levy, a leading spokesman for Israel's now majority population of immigrants from the countries of North Africa and the Middle East, is confident his time is coming, and soon.

Of the three, he is the least known outside Israel. Shamir was a prime minister, and is still the foreign minister, while Sharon was a domineering Army general and defense minister, the architect of the war in Lebanon. Levy is the minister of housing and construction.

Levy did not reach Israel until 1957, at the age of 20, when his family emigrated from Morocco. The large family was as poor in Israel as in Morocco, struggling to survive in Beit Shean, a barren "development town" for new immigrants in the northern Jordan Valley. Levy does not travel on the circuit that takes Israeli politicians before U.S. Jewish audiences because he is one of the few leading political figures here who does not speak English.

But speaking alternately in French and Hebrew during an interview this week in his large, comfortable office in East Jerusalem, Levy exuded confidence about his own political future. He said he would challenge Shamir if new elections were called and was confident that he would prevail and lead the party against Labor.

Political circumstances have dictated that Shamir and Levy adopt different tactics as each positions himself for the future. Shamir has a personal agreement with Peres to switch jobs in September 1986, making his primary task to hold on that long, keeping the shaky unity government intact until he can take over as prime minister.

Toward that end, Shamir has muted his criticism of Peres' initially favorable response to Egyptian President Hosni Mubarak's recent proposals for Middle East peace negotiations. "I won't criticize Mr. Peres," he said when asked about this. But Levy has been outspoken on the subject. The concept of "territory for peace," the Labor Party's formula for a peace agreement involving the West Bank and Gaza Strip, "is not only unacceptable, it is dangerous," he told an audience of West Bank Jewish settlers this week.

Levy also has begun to distance himself from the most controversial policies of both the Begin and Shamir governments, particularly the war in Lebanon. In January, he was one of only two Likud ministers to vote with Labor for a three-stage withdrawal plan.

That vote also helped to dissociate Levy from Sharon, his other party rival, who is so closely identified with the war. When both Shamir and Sharon later supported implementation of the second stage of the pullback plan, it appeared to many here that among the three rivals Levy again had demonstrated the keenest sense of the drift of Israeli public opinion. In the interview, Levy said he voted for withdrawal "in the same way that I voted to go to war when the PLO established itself in southern Lebanon.

"Lebanon has no stable government . . . We did what we had to do there for our security. There is nothing more to do, and we have to get out."

At the same time, Levy said he did not worry that Israel's withdrawal from Lebanon would be interpreted as a sign of weakness. "I don't think our ability to defend ourselves is open to question," he said.

With such pronouncements, Levy projects himself as a confident, hard-eyed pragmatist. He said that he has always wanted to strengthen U.S.-Israeli relations, but he is critical of what he sees as the Reagan administration's surrender to Syrian pressure when it withdrew the U.S. Marine contingent from Beirut last year.

"How is it possible to understand that when the U.S. sends the Marines to Lebanon, which could have been a turning point in the Middle East, and they are faced with the extremist policies of Syria, the U.S. announces that the Marines are only there to defend themselves?" he asked. "I told this to former Texas Republican senator John Tower. I told him that if you want to defend your soldiers, leave them at home."

A Levy government, if that is what lies in Israel's future, probably would not differ significantly from the brief Shamir government. Levy has already demonstrated a far more cautious attitude toward military adventures than either Begin or Sharon, but like all of his Likud colleagues he is committed to Israel's retention of the West Bank and Gaza Strip and wedded to the Camp David "autonomy" formula as the only acceptable basis for Middle East peace negotiations.

"I am against looking for another way," he said.

Levy's main interests appear to lie in domestic affairs. He said that he would want his government to stand for "social justice," by which he did not mean the socialism of the Labor Party, which he rejects, but a government that nurtures the abilities of all its citizens.

What he wants, Levy said, no doubt thinking of the hardships endured by his and other families of immigrants to Israel from North Africa and the Middle East, is a society where "no one will ask you where did you come from, but where are you going."