A cease-fire agreed to by all parties to the three-week-old war in Lebanon went into effect early this morning.

The truce was announced last night by Saudi Arabia's special envoy Prince Bandar Sultan and Syrian Foreign Minister Abdel Halim Khaddam at a press conference in Damascus. The agreement officially took effect at 6 a.m. (midnight Sunday EDT).

Christian Phalange radio reported that immediately after 6 a.m. five shells fired from rebel positions fell in the greater Beirut area, United Press International reported. But after that the beleaguered and battle-scarred capital remained quiet.

Even as the accord was announced last night, fighting flared again between the Lebanese Army and Druze militiamen around U.S. Marine positions at Beirut airport in the southern suburbs and at the strategic mountain town of Suq al Gharb.

At least three more marines were wounded yesterday, two by shelling and one by sniper fire. That brought Marine casualties during the past month to four dead and 38 wounded.

Khaddam said contacts between Syrian President Hafez Assad and Saudi King Fahd as well as among the various parties to the conflict had resulted in the accord.

"As a result of these contacts and efforts," he said, "an agreement has been reached to stop the war and fighting and to start a national dialogue between the conflicting parties."

Both Khaddam and Bandar called on the Lebanese to work together to find a political settlement to the crisis "in a spirit of dialogue."

A short time later, Lebanese Prime Minister Shafiq Wazzan made a statement over state radio saying, "May it be a blessed hour. We said it over and over again. Enough. Enough. Enough. Enough of misery. Enough of bloodshed. Enough of torture. Enough of destruction.

"This is the date all Lebanese have been hungry for a long time. Today we are at a new beginning, the end of wars and the beginning of sincere work at all levels for reconstruction."

An American official said a preliminary meeting to discuss the details of a formal conference of Lebanon's chief political and sectarian leaders would be held within a week "probably here" in Lebanon.

The formal conference is expected to open shortly in either Jiddah or Riyadh in Saudi Arabia, but it is unclear whether it will continue there for the months it is expected to take to get an agreement, or be transferred to a site inside Lebanon.

The delay in announcing the cease-fire was understood to be due partly to the late arrival of Bandar in Damascus and to the time necessary for him and Khaddam to go over the text of the accord.

U.S. special envoy Robert McFarlane initially informed Gemayel at 6:30 p.m. that an accord had been reached and that the cease-fire would go into effect at 7:30 p.m. (1:30 p.m. EDT).

President Reagan telephoned Gemayel shortly after 7 p.m. here to congratulate him on the agreement and to assure him of U.S. support in its implementation as well as in the tough political negotiations that lie ahead.

Gemayel, in turn, thanked Reagan for the efforts made by McFarlane and his assistant, Richard Fairbanks, in helping to arrange the cease-fire and said he regarded it as only a first step in "the march for peace" and Lebanon's efforts to remove all foreign troops from its soil.

Sources here said the agreement, which came after a breakdown in Saudi-led mediation efforts Friday, followed intense American diplomatic activity during the past 48 hours.

Saturday, it had appeared that chances for a cease-fire accord were doomed because of last-minute Syrian demands and Gemayel's refusal to take part in the national dialogue committee being set up to discuss Lebanon's future.

Press reports here yesterday said a whole new approach to the negotiations was being considered, and the reports expressed gloom over the prospects for any accord in the near future.

According to a Lebanese communique issued here last night, the agreement worked out by Saudi and American mediators calls for:

* An immediate cease-fire throughout all Lebanese territory "on all axes and points of contact," supervised by "neutral observers;" in addition, facilitation of the return of refugees forced to flee their homes since the 1975-76 civil war as well as of arrangements for relief operations.

* A committee to establish arrangements for the cease-fire and its consolidation, made up of the Army, the Phalangist Lebanese Front, the opposition National Salvation Front and the Shiite Amal movement.

* "An urgent and comprehensive meeting" to begin a national dialogue consisting of the three leaders of the National Salvation Front--former president Suleiman Franjieh, former prime minister Rashid Karame and Druze leader Walid Jumblatt; the heads of the Phalangist-led Lebanese Front--Camille Chamoun and Pierre Gemayel, who is the father of the president; Shiite leader Nabih Berri and three independent political figures: Sunni Moslem leader Saeb Salam, Adel Osseirane and Maronite Catholic leader Raymond Edde.

* Attendance at the meeting of delegations from Saudi Arabia and Syria.

The statement did not indicate who would represent the Lebanese government at the meeting but said it would include members from the legislative and executive branches.

Sources here said that the last sticking point over the membership of the national reconciliation committee had been resolved through a compromise that assured the Gemayel government would be represented on it but by someone other than the president.

Both Jumblatt and Berri had earlier insisted on the need for Gemayel to be present in the reconciliation committee to represent the government as one of the parties to the conflict.

They and the Syrians had refused to accept Wazzan and Parliament Speaker Kamal Assad on the committee, and Gemayel had then said he did not want to participate either.

Sources here said the two sides had agreed on a compromise candidate to represent the government: Bahaeddin Bsaat, a Sunni deputy and minister of electricity who is regarded as a relatively noncontroversial figure.

In return for the government's concession over direct participation in the committee, Syria and its Lebanese allies were understood to have agreed that all decisions made by its members would be by unanimous rather than majority vote. This in effect assures the Gemayel government a strong voice and veto.

The Syrian-backed opposition was said to have agreed to this only after the United States and Saudi Arabia assured its leaders that they would see to it that the Gemayel government would implement the committee's decisions and accept changes in the political status quo.

Earlier, Berri had told reporters he would refuse to join the reconciliation committee if Gemayel was not also present because, he said, "the aim is not only a cease-fire but . . . justice in the country and political reconciliation to try to build up a new Lebanon."

The committee is expected to discuss the formation of a new and broader coalition government and a revised power-sharing formula providing Moslem groups a larger voice in the traditionally Maronite-dominated political system.

Observers here felt that innumerable obstacles remained not only in making the cease-fire stick but also in getting Lebanon's long-feuding political titans, some of whom have refused to meet each other for years, to agree on a major redistribution of power.

The cease-fire is to be overseen by an armistice commission composed of the three warring militias--the Druze Progressive Socialist Party of Jumblatt, Berri's Amal Shiites and the Christian Phalangists--sitting together with the Lebanese Army.

U.N. observers, probably drawn from the U.N. Truce Supervisory Commission set up in 1948 to oversee the Lebanese-Israeli armistice, are to serve as "observers" but apparently not as enforcers of the cease-fire.