President Reagan expressed sorrow yesterday over the death of a U.S. Marine in Lebanon from a U.S.-made cluster-type artillery shell that accidentally exploded but made clear that the American troops will stay.

At the same time, administration officials privately said there was "a quiet mood of optimism" here that an agreement would be reached in coming weeks that would start a process of withdrawal of Israeli, Syrian and Palestinian forces from Lebanon.

While offering no specific reasons for the optimism, the officials said that Saudi Arabia and Syria were the key elements in getting this process started. The Saudis are being asked to persuade the Syrian government to begin withdrawing its roughly 30,000 troops from eastern Lebanon, while the Syrians are also pressured to prevent further incursions into eastern Lebanon by Palestine Liberation Organization fighters.

Israel has charged that many PLO fighters evacuated from west Beirut two weeks ago are returning to Lebanon by a "back door," presumably through Syria. American officials say it is important that Syria not give Israel any reason either to launch fresh attacks or to come back into Lebanese territory.

The officials noted that U.S. special envoy Philip C. Habib was now in Syria after talks in Saudi Arabia and Egypt. An Egyptian Foreign Ministry spokesman said in Cairo on Thursday that Habib had assured the Egyptian foreign minister that an agreement on the withdrawal of Israeli and Syrian forces from Lebanon would be arranged within a matter of weeks.

The 1,200 American Marines now in Lebanon along with another 1,000 troops each from Italy and France are part of a multinational peace-keeping force that will remain there until the Lebanese government says it has regained control of its country and until the other foreign forces withdraw.

Reagan has called the removal of the foreign forces the first step in a broader peace initiative he has proposed, involving creation of a self-governing Palestinian entity in the West Bank and Gaza regions "in association with Jordan."

Israeli Prime Minister Menachem Begin has rejected the Reagan plan. Yesterday he reaffirmed his objections in a letter to Sen. Alan Cranston (D-Calif.), a strong supporter of Israel who had urged Begin to reconsider.

But Begin again criticized the major provisions of the Reagan plan, calling it "an ultimate danger to our children, to our future, to our very existence."

Among other things, Begin said the president's plan would lead to a Palestinian state controlled by the PLO in alliance with Moscow. Begin also lashed out at what he said was a "fantastic . . . totally despicable" campaign to blame Israel for the massacre of Palestinian civilians in refugee camps in Lebanon.

"The first horrific truth is that Arabs killed Arabs," Begin wrote. "The second . . . is that Israeli soldiers stopped the carnage. And the third. . . is that if the current campaign should go on without a reaction of outrage by decent men, then -- within a matter of a few weeks or months -- everyone everywhere will have gotten the impression and will begin to believe that it was an Israeli military unit which perpetrated the horrible killings."

Pentagon spokesmen confirmed yesterday that Marine Cpl. David L. Reagan of Chesapeake, Va., was killed Thursday when an undetected 155mm cluster-type artillery shell blew up while he and some other Marines were attempting to clear such munitions from the area around Beirut International Airport.

Officials said privately that the shell -- the kind that spews out dozens of tiny, shrapnel-producing grenades -- was U.S.-manufactured. Thousands of these munitions were shipped to Israel in the 1970s; President Reagan ordered a halt to such shipments last summer after the Israeli attacks in Lebanon.