Moshe Arens, Israel's ambassador to the United States, agreed today to accept the post of defense minister, replacing Ariel Sharon, who formally gave up the post he has held since 1981 in a tearful ceremony at the ministry this morning.

Tonight, a subdued Knesset approved Prime Minister Menachem Begin's plan to retain Sharon in the Cabinet despite the severe criticism leveled at him by the commission that investigated the Beirut massacre.

Arens accepted the defense post, the second most powerful job in the Israeli government, in a telephone call to Begin today. Officials said he is expected to arrive in Israel late this week or early next week for several days of talks about his new duties. He will then return to Washington to conclude his affairs there before assuming the defense job.

The replacement of Sharon by Arens is not expected to change Israeli policy. The 57-year-old Arens is as hawkish as his predecessor and Begin, particularly on the key issue of the future of the occupied West Bank and Gaza Strip.

Arens, who was born in Lithuania, emigrated to the United States at the age of 14 and moved to Israel in 1957. He trained as an aeronautical engineer at the California Institute of Technology and the Massachusetts Institute of Technology and later designed aircraft and missiles in Israel. His appointment must still be approved by the Knesset.

The Knesset, by a vote of 61 to 56, approved the decision of the Cabinet yesterday to transfer temporarily the defense minister's duties to Begin until Arens is officially installed. The plan allows Sharon, condemned by the inquiry commission for the "grave mistake" and "blunders" that led to last September's massacre, to remain in the Cabinet as a minister without portfolio, without specific duties but with a continuing place in the Israeli government's executive body.

The inquiry board recommended that Sharon resign from the government or, if he refused, that Begin fire him. The shuffle of Cabinet responsibilities as a way around this was denounced in a front-page editorial in the independent newspaper Haaretz today as making a "farce" of the commission's report.

But this and other widespread criticism of the Cabinet shuffle had no impact on the floor of the Knesset, where the Begin government's coalition holds a four-seat majority in the 120-member body. Opposition Labor Party leader Shimon Peres conceded defeat at the outset of today's debate, saying, "The Cabinet will have a majority today in the Knesset, but will the country have a good example of proper behavior in a democratic society?"

The Labor Party decided last night to bring a motion of no confidence in the government over the issue before the Knesset on Wednesday, but with no apparent expectation that it will succeed.

Peres devoted much of his speech to hurling back at Begin his own public statements after a similar inquiry commission, established to investigate Israeli military and intelligence failures before and during the 1973 war, recommended actions against senior military officers but not against their civilian political superiors. Begin, at the time a leader in the opposition, demanded the resignation of the Labor Party government headed by Golda Meir.

"This is how you educate the public, the young people? This is a parliamentary democracy?" Peres quoted Begin as saying when he was demanding the downfall of the Labor government.

"The spirit of the [massacre commission] report is that Ariel Sharon must leave the government," Peres said. He called on Israelis to preserve their heritage and not allow the government to "play games with it."

The opposition leader also said that immediately after release of the massacre commission report last week, Begin considered resigning himself but was talked out of it by political associates. The prime minister, in his seat on the Knesset floor, spoke out, denying the assertion.

Both Peres and Begin eulogized Emil Grinzweig, the peace activist who was killed by a hand grenade explosion at a demonstration outside Begin's office during a Cabinet meeting Thursday night, and they urged Israelis to keep their political differences within bounds.

Begin spoke for only three minutes, outlining the Cabinet's decision to transfer the defense minister's duties temporarily and to retain Sharon in the Cabinet.

In Tel Aviv this morning, Sharon was accorded a ceremonial farewell with full military honors by Israeli military leaders and Defense Ministry employes as a military band played nearby.

In his last speech as defense minister, Sharon again disputed the commission's main finding that Israel bears "indirect responsibility" for the Beirut massacre and said he thought it important that he remain in the government.

Sharon said his policy had always been to maintain a strong deterrent force in Israel and use it when necessary and that he was not sure such a policy would now be followed.

Numerous questions remain about what duties and powers Sharon will be given by Begin and whether he will be allowed to remain a part of important committees within the Cabinet such as the one that directs Israel's policy in the negotiations for a troop withdrawal from Lebanon.

Even before the Knesset vote, senior government officials sought to make the commission's report a thing of the past. Speaking to a visiting delegation from the European Parliament, Begin said the internal turmoil caused by the inquiry board's findings would have no impact on the Middle East peace process.

Foreign Minister Yitzhak Shamir, who was criticized by the commission for ignoring a report of the massacre while it was still going on, told the same group that the events of the last week vindicated Israeli democracy. "Our democracy has just undergone some trying days," he said. "It was a test of our commitment to those values, and we passed the test. Our friends abroad were anxious, and our enemies gleefully hoped for our weakening and breakdown. We can say today with confidence that Israel is safe, its democracy is sound as ever and it will continue on its present path toward peace and security."