Rival Palestinian factions Hamas and Fatah signed an agreement in principal to form a unity government during the second day of emergency talks Thursday, according to reports. 

Khaled Mashaal, leader of the militant Hamas group, and Palestinian President Mahmoud Abbas of the more moderate Fatah party, signed the accord at a ceremony hosted by Saudi King Abdullah in a palace overlooking the Kaaba, Islam's holiest shrine in Mecca, The Associated Press reports.

The deal sets out the guidelines for the coalition government, including a pledge that it will "respect'' previous peace deals with Israel, delegates said.

The two factions had earlier agreed on the distribution of key cabinet posts within a unity government.

Hamas, which took power with an election victory more than a year ago, and Abbas' Fatah party have been in a deadlock for months over key issues.

Points of contention included Hamas' unwillingness to renounce violence or recognize Israel's right to exist, and control of security forces.

The two sides appear to have reached a compromise during the crisis talks.

"We have agreed to form a national unity government. The agreement will be signed very soon," Palestinian ambassador to Saudi Arabia Jamal al-Shobaki told Reuters.

Al Jazeera television also reported that a deal had been reached. The Arab television network said delegates from Hamas and Fatah would meet with Saudi King Abdullah after the signing.

There is no word yet on the disagreements the two sides were able to resolve.