The leaders of Israel's two major political blocs said today they were nearing agreement on a joint government of national unity but that important details still were to be resolved. They said a pact could be drawn up early next week.

Politicians from both blocs confirmed that Labor Alignment leader Shimon Peres and Prime Minister Yitzhak Shamir, leader of the rival Likud, have agreed to alternate in the job of prime minister and to divide Cabinet posts equally in a new government. But they added that the two leaders still must convince their political colleagues to go along and will seek to persuade allies among the minority parties to join.

The selection of Cabinet portfolios for each bloc and final resolution of who would be first prime minister also remained to be worked out, according to the sources, who said these matters could delay a final settlement. Israeli radio, in the initial report not long after midnight, said the two had agreed that Peres would take the first turn as prime minister.

Peres and Shamir, after two hours of private talks this afternoon, confirmed they had agreed that a joint government would rule for four years and two months -- that is, until the next regularly scheduled election. But they refused comment on the issues of alternating the prime minister's job or Cabinet posts.

"We made . . . headway yet our work is not completed -- we shall have to continue," Peres told a press conference. He said that "there are still one or two items" that he hoped could be resolved "by Sunday or Monday."

Shamir said he expected an agreement "very soon." The two agreed to meet again Sunday.

While Peres and Shamir appeared cautiously optimistic that a settlement was imminent that would break Israel's 39-day electoral deadlock, some of their political colleagues were less sanguine.

Although Shamir reportedly is prepared to serve under Peres for the first 25 months, some of the hawks in the right-leaning Likud, reportedly including caretaker Deputy Prime Minister David Levy and former defense minister Ariel Sharon, are said to be insisting that Shamir get the first nod.

Israeli radio quoted a high-level Likud leader tonight as saying, "It is not the law from Sinai that Shimon Peres get to be prime minister first." Peres had strongly and publicly opposed alternating the prime minister's post, arguing that such a system would prove unwieldy and that he deserved the post because Labor won 44 seats to Likud's 41 in the July 23 parliamentary election. Both sides fell far short of a majority in the 120-member Knesset.

Despite adding three seats from former Likud defense minister Ezer Weizman's Yahad Party last week and a fourth from an ally of Weizman, Labor was not able to entice enough of the 13 minor parties holding Knesset seats to reach a firm majority.

Peres was left with two choices: accede to sharing the premiership with Likud or opt for a new election that most analysts believe would prove equally indecisive. In choosing the former, he reportedly insisted that he should serve first as prime minister and that Labor hold the defense portfolio for the entire 50 months. Should the remaining talks fail, the option of a new election would remain.

Some Likud members reportedly are prepared to serve under Peres first, but only if Likud is granted both the defense and foreign ministries. But Peres is believed to have already promised defense, considered Israel's most important ministerial post, to former Labor prime minister Yitzhak Rabin, a bitter party rival of Peres who buried his differences with him during the recent election campaign in return for this pledge.

Shamir also faces a right-wing revolt from the five-seat Tehiya Party, which is ideologically committed to the maximum settlement of Jews in the occupied West Bank and ultimately to the annexation of the territory.

Tehiya Knesset member Geula Cohen, whose party was a coalition partner of Likud in the last Likud-led government, said today her group could not support a national unity government in which the fate of future settlements would be determined by a majority Cabinet vote.

At the same time, Peres is threatened by a left-wing revolt from the six-seat Mapam Party, the junior partner in the Labor Alignment.

Mapam leader Victor Shemtov said tonight his party opposed joining a coalition with Likud but added that it would make no final decision until Peres and Shamir had concluded their negotiations.