Hamas and Fatah security officials traded fire at Gaza's border with Egypt on Tuesday as Prime Minister Ismail Haniyeh passed through on his way to reconciliation talks between his Hamas movement and the rival Fatah group in Saudi Arabia, witnesses said.

Haniyeh, who was in a VIP hall and not in the immediate area of the firefight, crossed to Egypt unharmed, they said. He had arrived at the border crossing under heavy guard after traveling along a route lined with hundreds of Hamas gunmen on foot and in jeeps.

Although Haniyeh expressed confidence that the reconciliation talks would end months of Palestinian infighting, Tuesday's gunbattle was an ominous sign for the meeting in Mecca, which analysts have said could be the two sides' last chance to avert civil war.

• Visit FOXNews.com's Mideast Center for more in-depth coverage.

The 10-minute gunbattle at the border terminal caused no injuries, said the witnesses, who demanded anonymity because of safety concerns.

Fatah and Hamas security officials offered a different version of events. They said shots were fired in the air to disperse a crowd of thousands of people who had tried to push through the border crossing after Haniyeh.

The passage — Gaza's gateway to the outside world — has been closed to outgoing traffic since Jan. 8 because of Israeli security alerts.

The two groups have been clashing ever since Islamic Hamas militants unseated President Mahmoud Abbas' long-ruling Fatah in parliamentary elections last year. Although the separately elected Abbas remained in power, with considerable authorities, Hamas' violently anti-Israel ideology has drawn punishing sanctions by the West and Israel.

Abbas hopes a Hamas-Fatah coalition government would end the factional violence and the sanctions.

Earlier rounds of talks, some brokered by Egypt, Syria and Qatar, foundered over Hamas' refusal to recognize Israel's right to exist. Israel and Western donor countries have said their sanctions won't be lifted until Hamas softens its position.

The negotiations follow an especially bloody round of factional violence. More than 30 people were killed and more than 200 were wounded in four days of fighting before the factions ceased fire on Sunday.

Before setting off on the trip from his house to the border, Haniyeh sounded upbeat about reaching a power-sharing agreement with Fatah.

"We will do all within our power to reach a Palestinian agreement on national unity government," said Haniyeh, whose delegation is to be led by Hamas' exiled leader, Khaled Mashaal. "We are optimistic and hopeful that we will succeed, and return to our people with an agreement that can heal our wounds and end the tension."

A senior Fatah official predicted the two sides would conclude an agreement in Mecca.

Kadoura Fares, a former Cabinet minister who met with Mashaal in his Syria headquarters last week, told Israel's Army Radio that nearly all obstacles have been overtime during talks in recent weeks.

Complete coverage is available in FOXNews.com's Mideast Center.