In a ceremony rich with symbolism but temporarily threatened by a last-minute complication, Egypt and Israel formally ended a 30-year state of war today by exchanging articles of ratification of their historic peace treaty.

What was to have been a pro forma occasion almost soured unexpectedly as about 400 dignitaries and reporters gathered in a remote U.S.-manned early warning station here and waited 2 1/2 hours after the scheduled start of the ceremony while Egyptian and Israeli officials argued about the documents to be exchanged.

The dispute, which centered on a missing word in the Egyptian text of the portion dealing with Palestinian autonomy, finally was resolved. Then the treaty was officially executed at 5:27 p.m., when Egyptian and Israeli representatives passed to each other certificates attesting to parliamentary approval by both nations.

"The war is over. Long live the peace," proclaimed Eliahu Ben-Elissar, Israeli Prime Minister Menachem Begin's director-general, as Egyptian and Israeli military bands jointly played the two countries' national anthems.

Saad Afra, Egypt's undersecretary of state for foreign affairs, glanced at Israeli and Egyptian honor guards and said, "I would like to salute all these soldiers present who, only some months ago, stood in confrontations before each other and now are eagerly witnessing the flag of peace being hoisted."

The unlikely setting for the emotion-charged ceremony was a motel-like compound of squat brown buildings that serve as headquarters for the U.S. Sinai field mission, which monitors Egyptian and Israeli electronic surveillance and operates sensor fields to detect troop movements in the eastern and western ends of the Mitla and Gidi Passes.

[The Soviet news agency Tass reported the ceremony, saying it was held in the remote area because the nations involved were "scared by the broad protest" of the "treacherous deal" in the Arab world and wanted as little fanfare as possible, Associated Press reported.]

Here, in a makeshift parade ground in a recreation center parking lot, four flags-U.S., Israeli, Egyptian and U.N.-snapped in a brisk wind as politicians and military honor guards from Egypt and Israel gathered.

It was the first time since the founding of Israel in 1948 that Israeli soldiers stood side-by-side with an Egyptian guard and that military bands from both nations played jointly.

The ceremony appeared to begin without a hitch at 3 p.m. when the military bands began playing spirited martial music, and the guests began craning for a glimpse of heads of delegations.

As time passed, guests began exchanging embarrassed glances. The military bands kept up a marathon of music, as harrassed-looking officials spoke of "slight delays" and looked nervously toward the building where Ben-Elissar, Afra and their legal advisers were conferring.

In a once-undreamed of gesture, Israeli and Egyptian soldiers standing ceremoniously at the end of their respective formations began talking to one another out of the sides of their mouths. The Israeli soldier, a Moroccan immigrant, later said he asked the Egyptian in Arabic what he thought of peace, and the Egyptian replied it was a pity that young children have been lost in wars.

The spectators became increasingly restless when an official announced that the honor guards would leave and that refreshments would be served. Rumors of an indefinite postponement of the treaty exchange swept through the crowd.

During the next two hours of waiting, the military bands and honor guards showed considerably more amiability than their leaders appeared to be sharing in the nearby conference quarters.

They began mingling in a adjacent lot, playfully exchanging helmets and berets while posing for photographs and shouting to each other, "No more war, no more bloodshed."

Several Israeli soldiers tried to explain to the Egyptians the religious significance of the skull caps they were wearing under their berets. An Egyptian soldier, obliging photographers, tried to kiss an Israeli woman soldier as she blushingly pulled away.

The soldiers showed each other their rifles and an Israeli clarinetist recruited an Egyptian clarinetist and trombone player for an impromptu jam session. The three quickly agreed on a lively melody, to the delight of band members from both countries.

Other soldiers and invited dignitaries signed and exchanged Egyptian and Israeli currency.

Finally, nearly 2 1/2 hours behind schedule, the problem with the text was resolved, the documents were exchanged and the flags of both countries raised.

Recalling the peace negotiations breakthrough earlier this year that led to the treaty, Ben-Elissar said:

"It were as if both our nations, associated for all time by our ancient geography, heritage and culture, have made their rendezvous with history."

The issue causing the last-minute delay was one that has stalked the negotiations throughout the peace treaty.

Ben-Elissar said the countries had agreed that autonomy on the West Bank and Gaza Strip should apply to "inhabitants" rather than to the territories, and that this key word was missing from the Egyptian text.

He said a draft letter correcting the omission was eventually drawn up on the spot and that it will be signed by the Egyptian and Israeli leaders.

Meir Rossenne, legal adviser of the Israeli Foreign Ministry, reportedly raised the objection upon examining the Egyptian document.

Rossenne would not discuss the dispute afterward, saying only, "The birth was not a very easy one, but we hope the baby is in good shape." CAPTION: Picture, Eliahu Ben-Elissar, left and Saad Afra embrace.UPI