The Palestinian rival Hamas and Fatah factions agreed to form a national unity government after two days of intensive negotiations and resolved to end months of violence between the groups.
Palestinian sources said Hamas' Ismail Haniya would remain prime minister, while the divisive interior and foreign ministries will be taken over by independents.
Fatah named Ziad Abu Amr, an independent close to Fatah, as foreign minister. Hamas will choose an independent as interior minister - the largest sticking point in previous talks.
Fatah will appoint a deputy to Haniya, the sources added on Thursday.
Palestinians hope the unity government will put an end to ongoing violence between the two factions in the West Bank and Gaza Strip.
The sides agreed to end all internal fighting and reform the Palestinian Liberation Organisation (PLO).
But there was no clear word on the platform of the new government, specifically whether Hamas agreed to accept the key demand of the international quartet - the US, the European Union, Russia and the UN - to recognise Israel.
Speaking at a signing ceremony in Mecca, Palestinian President Mahmoud Abbas of Fatah wished "full success to the new government" and said he hoped this agreement "will lead to an end to the violence".
Abbas hopes a unity government will ease an economic and diplomatic boycott by western nations, imposed on the Palestinian government after Hamas won power in elections last year.
The quartet has demanded that Hamas renounce terrorism and honour past Israel-Palestinian agreements.
According to the points reached in Mecca, the new government will "respect" all previous agreements signed by the PLO, but Israel is not mentioned.
Also, the PLO will continue to be responsible for negotiations with Israel, and not the new government.
Israeli foreign ministry spokesman Mark Regev said late Thursday that "any Palestinian government which wants international recognition must recognise Israel, renounce terrorism, and accept signed agreements in the peace process, including the road map" - a quartet-sponsored peace plan.
The US also said any new Palestinian government must renounce violence and accept Israel's right to exist as part of conditions to win US support.
"It's important to have a government that will be a full negotiating partner with Israel," White House spokesman Tony Snow said shortly before the agreement was announced.
Under the deal, Hamas will not have a majority of the government ministries, but will hold the most of any faction, according to the Palestinian sources.
Hamas will receive eight ministries, while Fatah will get six. Another six portfolios will be divided between independents.
Salam Fayyad, a member of a former Fatah-led government and now part of a smaller faction, will become finance minister, according to the sources.
During the ceremony in Mecca, Haniya called for the right to return of Palestinian refugees to the homes that they fled during the 1948-49 Arab-Israeli war, and for Israel to release Palestinians held in its jails.
Calling for a "new era of resistance", Haniya said he would work to remove the international boycott on the Palestinian government.
Palestinian sources say Hamas would get the ministries of education, al-Waqf (Islamic property), labour, municipal affairs, sports and youth, economics, justice and communication. Fatah would get health, social affairs, public work, transportation, agriculture and prisoners' affairs.
Addressing sceptics of the latest Palestinian agreement, Khaled Mashaal, the Damascus-based Hamas leader, said they "are wrong and we pledge to uphold these agreements".
King Abdullah of Saudi Arabia, who hosted the meeting, said the talks would hopefully serve to "alleviate the suffering of the Palestinian people".
The bitter internecine fighting between Fatah and Hamas has claimed 87 lives since the beginning of the year, according to the UN Office for the Coordination of Humanitarian Affairs.