Of the 132 seats in Parliament, Hamas won 76 and Fatah 43, the election commission announced on Thursday.
Ahmed Qureia, the Palestinian prime minister, and his cabinet resigned, even before the official results were announced, and Mahmoud Abbas, the Palestinian president, was to ask Hamas to form the next government.
The top Hamas leader, Khaled Mashaal, told Abbas his group is ready for a political partnership, Hamas said.
And in a first sign of pragmatism, Mahmoud Zahar, a top Hamas official, said the group would extend its year-old truce if Israel reciprocates. "If not, then I think we will have no option but to protect our people and our land," he said.
Saeb Erekat, the Fatah legislator, said the party does not want to join a Hamas government. "We will be a loyal opposition and rebuild the party," Erekat said, after meeting Abbas.
But Nabil Shaath, another senior Fatah legislator, said the party's leadership would make a decision later.
Abbas will remain president
Abbas was elected separately a year ago and remains president. However, the Palestinian leader has said he would resign if he could no longer pursue his peace agenda.
The cabinet and legislature must approve any major initiative by Abbas, giving Hamas tremendous influence over peace moves.
Hamas supporters streamed into the streets to celebrate.
In the southern Gaza town of Rafah, supporters shot in the air and handed out candy. Others honked horns and waved Hamas flags from car windows.
Hamas capitalised on widespread discontent with years of Fatah corruption and ineffectiveness. Much of its campaign focused on internal Palestinian issues, while playing down the conflict with Israel.
Before the election, Hamas had suggested it would be content as a junior partner in the next government, thus avoiding a decision on its relationship with Israel.
Throughout the campaign, leaders sent mixed signals, hinting they could be open to some sort of accommodation with Israel. Its apparent victory will now force it to take a clearer position on key issues.
Final results results are to be certified within twoweeks. During that time, participants may challenge results.
After final results are in, Mahmoud Abbas, the president
of the Palestinian Authority, begins consultations with
factions that are to enter the next parliament, then will tap a party to put together a government. That party will
have three weeks to put together a government, and can ask for a two-week extension.
The new Palestinian parliament is to be sworn in for a four-year term in March.
Abbas, elected last year to a four-year term, can remain in office. He has said he would step down if he cannot push
forward efforts to seek a peace deal with Israel.
Mushir al-Masri, a Hamas candidate who won election in the northern Gaza Strip, said peace talks and recognition of Israel are "not on our agenda" but the group is ready for a partnership - presumably with Abbas.
Some Hamas officials tried to reassure the world of its intentions.
"Don't be afraid," Ismail Haniyeh, a Hamas leader, told the BBC. "Hamas is a Palestinian movement, it is an aware and mature movement, one which is politically open in the Palestinian arena, and to its Arab and Islamic hinterland, and similarly open to the international arena."
This was the first time Hamas has contested a parliamentary vote.
Half the seats in Wednesday's parliament vote were chosen on a national list and the other half by districts.
Hamas apparently took advantage of divisions in Fatah: the long-ruling party fielded multiple candidates in many districts, splitting the Fatah vote.
"Hamas is a Palestinian movement, it is an aware and mature movement, one which is politically open in the Palestinian arena, and to its Arab and Islamic hinterland, and similarly open to the international arena"
Hanan Ashrawi, the Palestinian legislator, who apparently was re-elected on a moderate platform, said the Hamas victory was a dramatic turning point.
She said she is concerned the fighters will now impose their fundamentalist social agenda and lead the Palestinians into international isolation.
She said Fatah's corruption, Israel's tough measures and international indifference to the plight of the Palestinians were to blame for Hamas's strong showing.
Turnout for Wednesday's vote was heavy, with nearly 78% of 1.3 million eligible voters casting ballots. The polling stations were heavily guarded, and there were no reports of major violence.