Israel's Labor party formally agreed tonight to join its rivals from the Likud bloc in a "government of national unity," clearing the last major hurdle standing between Labor leader Shimon Peres and the post of prime minister.

The Labor party central committee, after a stormy six-hour debate, approved the terms of the agreement with the Likud by a vote of 394 to 166. The vote climaxed seven weeks of intense political maneuvering following the inconclusive outcome of the July 23 national election here that left both Labor and the Likud unable to assemble a 61-seat parliamentary majority.

The Likud central committee is expected to approve the agreement and party leader Yitzhak Shamir's choices to fill the Likud positions in the Cabinet on Tuesday. Parliament is scheduled to meet Wednesday for a confidence vote in the government to be presented by Peres, the prime minister-designate.

Under the terms of the Labor-Likud agreement, Peres is to be Israel's prime minister for the next 25 months, while Shamir serves as foreign minister and acts as prime minister when Peres is out of the country. During the second 25 months of the government's span, if it survives that long, Peres and Shamir are to reverse their roles, with the Likud leader taking over as prime minister.

Other Cabinet posts are to be split evenly between Labor and Likud officials, according to the terms of the accord.

This arrangement is widely viewed here as cumbersome at best and possibly unworkable in the long run. Its great virtue is that it would end the state of deadlock and political paralysis that has afflicted Israel for the past seven weeks and avert the need to call new national elections immediately.

"I'm afraid at this stage that I don't see any alternative, even for those who oppose the agreement, except to let it through and see what happens next," said Abba Eban, a foreign minister in previous Labor governments, before tonight's vote.

Peres, the sleeves of his blue shirt rolled up as he addressed his colleagues in a sweltering Tel Aviv meeting hall, used the "no alternative" argument to beat back his opponents. He also pledged to withdraw Israeli troops from southern Lebanon, but set no timetable to accomplish this.

"I have no fear and no second thoughts and no doubts about the way we have chosen or about our stamina," Peres said.

The new government's first task almost certainly will be to tackle Israel's deep economic problems. Outgoing Likud Finance Minister Yigal Cohen-Orgad said today that the government will ask the United States for between $750 million and $1 billion in emergency aid in addition to the $2.6 billion in military and economic assistance that Congress is expected to provide for the fiscal year that begins Oct. 1.

The Reagan administration has indicated its willingness to support an emergency economic package for Israel, but only if the aid request is accompanied by what U.S. officials describe as meaningful reforms in the Israeli economy that would dampen the country's 400 percent inflation rate.

Tonight's central committee vote put Peres as close as he has ever been to the position he has sought, without success, since 1977. Peres led Labor to defeats by the Likud in 1977 and 1981. In the July election, Labor won a narrow plurality in Parliament, but it was less than a complete victory because Labor and its allied parties were unable to form a government on their own.

Peres was thus forced to seek a compromise with the Likud and to argue to his own divided and discontented party that the only alternative to a unity government was new elections in which Labor might not win as many seats as it did in July.

Most of the opposition to the deal with the Likud came from the left wing of the Labor Alignment. The opponents charged that under the agreement Likud officials would be placed in charge of Israel's economic policy at a time of economic crisis, and that a government that included the Likud would continue to build Jewish settlements in the occupied West Bank, a policy that Labor pledged to halt.

Many critics also said that no Labor party official should agree to sit in the same government with former Likud defense minister Ariel Sharon, described by Labor as the architect of Israel's "disastrous" invasion of Lebanon in 1982. Sharon is slated to be the minister of industry and trade in the proposed unity government.

In the end, however, these objections were overcome by the lure of a return to government power for Labor -- even if that power has to be shared with its bitter rivals -- and fear about the outcome of new elections if the deal with the Likud fell apart.

But the price Peres paid to reach an agreement with Shamir was the loss of much of his own party's left wing. The Mapam faction of the Labor Alignment, which has six members in the new Parliament, voted overwhemingly last night to bolt from Labor and go into opposition.

Yossi Sarid, an outspoken left-wing Labor party member, also resigned from the party and announced that he will join the three-member Citizens Rights Movement in Parliament. The Citizens Rights Movement, a traditional ally of Labor, earlier decided it would not join a unity government with Likud.

In the July election, Labor won 44 seats in Parliament and the Likud 41, leaving both far short of the 61-seat majority in the 120-member body that is necessary to form a government. The remaining parliamentary seats were scattered among 13 other small parties, the bulk of them ideologically closer to the Likud than to Labor.

It was clear from the outset that Labor and its natural allies in Parliament had virtually no chance of forming a government on their own. The Likud and its allies appeared to be in a slightly stronger position until former defense minister Ezer Weizman, who had made no pre-election commitments, aligned his new three-member party with Labor.

The move by Weizman effectively meant that neither Labor nor the Likud could form a government without help from its main rival. This set off the negotiations for a unity government.