Marwan Bishara, Al Jazeera's Middle East analyst, said: "This is an important agreement. It's a milestone."
He said the new government was "a wonderful combination" that would represent a "mixed bag of all sorts of Palestinian factions".
At a signing ceremony described as the "Mecca Declaration," Abbas said: "We have achieved results that will serve our people. I hope that this will put an end to shameful actions."
"If these two factions unite, will they leave Israel alone and get on with furthering the fortunes of their own people?"
Bainatluc, Kitchener, Canada
Abbas and Khaled Meshaal, the exiled leader of Hamas, signed the deal in a palace overlooking the Kaaba, Islam's holiest shrine.
As part of the agreement Mahmoud Abbas, the Palestinian president, asked Ismail Haniya, the current Hamas-nominated prime minister, to form the new government.
Haniya will remain as prime minister, but the names of the new cabinet ministers were not announced at the ceremony.
The deal sets out the principles of the coalition government, including a promise that it will "respect" previous peace deals with Israel, delegates said.
Meshaal said the accord "will unify our ranks. There is a commitment and unity. We will preserve this partnership".
In Gaza City, which has seen much violence in recent weeks, residents waved flags and danced in the streets, while some Fatah and Hamas members fired guns into the air to celebrate the accord.
"The way ahead"
Ban Ki-Moon, the UN secretary general, said in a statement he looked forward to discussing "the way ahead" and he hoped the accord "will curb the violence, creating a better future for the Palestinian people."
The US did not immediately comment on the deal, but earlier on Thursday Condoleezza Rice, the US secretary of state, said that any Palestinian government would have to recognise Israel's right to exist, renounce violence and comply with earlier Israeli-Palestinian peace accords.
Miri Eisin, spokeswoman for Ehud Olmert, the Israeli prime minister, also said that Israel expected "the new Palestinian cabinet to respect the three principles laid down by the international community".
Mike Hanna, reporting for Al Jazeera's from Jerusalem, said: "It has been made clear that Israel is looking for an explicit recognition of Israel and an explicit renunciation of violence."
Meshaal said it was vital that the deal be respected by world powers.
"The international community must respect our accord, recognise our Palestinian reality and deal with it seriously," he said.
Since Hamas formed a government in March last year western powers have suspended aid contributions to Gaza, sparking an economic crisis in the Palestinian territories.
|Palestinian leaders met in Mecca|
to finalise the agreement [Reuters]
Al-Quds, a Palestinian newspaper, said that by reaching the agreement "the Palestinians are moving the ball into the Israeli-American-European court."
It said: "Israel no longer has any pretext to boycott Hamas."
But Yediot Aharonot, an Israeli newspaper, described the agreement as a great victory for Hamas.
"Khaled Meshaal and Ismail Haniya could not have hoped for more ... Hamas did not yield and it emerges greatly strengthened in the internal Palestinian arena and greatly strengthened in the Arab and international arenas," it said.
King Abdullah, Saudi Arabia's ruler, who hosted the Palestinian leaders congratulated both sides for "having risen to their responsibility ... by stopping the flow of blood and realizing national unity".
Meanwhile, Mikhail Kamynin, Russia's foreign ministry spokesman, was quoted by the Interfax news agency as saying: "We welcome any forward movement toward the creation of a national unity government, since only in this way can the situation in the Palestinian territories realistically be normalised."