President Anwar Sadat and Prime Minister Menachem Begin conferred unexpectedly here last night on the eve of the signing of the Egyptian-Israeli peace treaty and agreed that Begin will visit Cairo next Monday to seal the new friendship between the two former adversaries.

The hastily scheduled evening meeting between the two leaders appeared to be the final gasp in the 15-month-long bargaining marathon that produced the peace agreement Sadat and Begin are to sign at the White House today in the presence of President Carter.

Announcing the meeting on a television interview program yesterday, Begin said he would propose to Sadat to hold formal signing ceremonies in Cairo and Jerusalem as well as in Washington. But Sadat had already voiced opposition to this proposal, and evidently offered Begin an invitation for a oneday visit to Cairo as a compromise.

The two leaders also discussed a last-minute hitch that developed over the timing of the return of oil fields in the Sinai Peninsula to Egyptian control. Sadat told Egyptian reporters after the meeting that all pending problems had been resolved and that the formal signing of the treaty would go ahead today.

Sadat and Begin emerged from their 90-minute encounter at the Egyptian ambassador's residence here smiling and in good humor, according to Israeli officials. Begin announced the invitation from Sadat to a group of Egyptian editors standing inside the residence.

Israeli officials said the visit would be a reciprocal one for the journey Sadat undertook to Jerusalem in November 1977.

That trip opened the way for negotiations to end the 30 years of warfare and antagonisms between the Arabs and Israelis. Despite nearly unanimous condemnation or silence from other Arab nations, Sadat opened talks with Begin the following month and came close to agreeing on a peace treaty before the talks collapsed.

President Carter revived the peace effort by calling the Camp David summit last September and getting Begin and Sadat to agree to the bilateral treaty they will sign today and to a looser set of arrangements for further negotiations on Palestinian rights in the West Bank and Gaza Strip territories.

The last-minute hitch Sadat and Begin evidently resolved last night involved Egypt's demand that Israel turn over the Sinai oil fields within six months of the treaty signing. Israel wants to retain the fields for nine months as part of the initial phased Israeli withdrawal from the Sinai.

Israeli Foreign Minister Moshe Dayan said on ABC-TV yesterday that Begin also was asking Sadat for additional assurances that Egypt would sell Israel the same amount of oil that Israel now gets from the wells. Speaking before the Begin-Sadat meeting, Dayan said the problem was serious enough to put off the treaty signing. But Israeli officials said later it would go ahead.

Begin flew to Washington from New York in mid-afternoon and was greeted by several hundred persons who braved intermittent rain to welcome him at Andrews Air Force Base. Heading the official U.S. party were Vice President Mondale and Secretary of State Cyrus R. Vance.

"Tomorrow, with God's help, we shall lay the cornerstone and on it in the days and months to come we shall build the edifice of peace," Begin said. Calling on Sadat to open the borders between Egypt and Israel as soon as the treaty is signed, Begin said he was praying that the treaty would "indeed be the beginning of a comprehensive peace throughout the Middle East."

In their separate television appearances, Begin and Dayan reiterated their strong contention that the Camp David agreements specifically bar the establishment of a Palestinian state on the West Bank and in Gaza. Begin also maintained his absolute refusal to consider any dealings with the Palestine Liberation Organization under any circumstances, and branded Jordan's previous rule over the West Bank as "illegal."

Before leaving Dallas to return to Washington last night at the end of a two-day political trip, President Carter told a press conference that the Egyptian-Israeli peace treaty would be viewed in history as the most significant event of his term in office. He said that he thought the Egyptian-Israeli peace would be permanent.

The difficult Palestinian question had to be addressed now, Carter said, adding that it would be much easier now to bring Jordan, Syria, Iraq and the Palestinian Liberation Organization into the process once they saw the benefits of peace, according to news agencies.

But he also warned that a brief period of "threats, posturing and possibly some acts of terrorism" may follow the treaty signing.

The three leaders will sign copies of the treaty text in English, Hebrew and Arabic. They will also exchange agreed on sets of interpretations of the treaty's main clauses, treaty annexes spelling out the phases of Israeli withdrawal from the Sinai, and a jointly signed letter committing the three countries to open negotiations within one month on self-rule for the West Bank and Gaza.

The withdrawal of all Israeli troops from Sinai is to be completed within three years. Ambassadors are to be exchanged between the two nations after an initial phased Israeli pull-back is completed nine months from now.