Palestinian gunmen opened fire and tossed a grenade at the local headquarters of Israel's Likud Party here today, killing at least six people as voters were casting ballots in a nationwide primary in which they selected incumbent Ariel Sharon as Likud's candidate for prime minister in January's general election.

Witnesses said two gunmen opened fire with automatic weapons as voters lined up in front of the Likud headquarters in this northern town, spraying hundreds of bullets at the party office as workers and voters screamed and dived for cover. About 20 people were injured, 13 of them seriously.

"The terrorists were shooting, people were running in all directions, escaping like flies," said Simon Asayag, 41, who watched the attack from the roof of his apartment building about 100 feet away. "Neighbors were screaming, afraid that family and friends were there. The terrorists were shooting and shooting in all directions. They were spraying anyone who was in the area. When they ran out of bullets, they reloaded their magazines and nobody stopped them."

The attack came about six hours after three Israelis were among those killed when suicide bombers struck an Israeli-owned beach hotel outside Mombasa, Kenya, and other assailants fired two shoulder-launched missiles at a Tel Aviv-bound airplane with 261 passengers, most of them Israelis, that had just lifted off from the Mombasa airport. The missiles missed their target and no one was injured.

The carnage provided a backdrop for an election in which the security of Israel and its citizens is the dominant theme. Likud voters today overwhelming selected Sharon, an ex-army general who has orchestrated a tough military campaign against Palestinians fighting to end Israeli occupation of the West Bank and Gaza Strip, as their candidate for the Jan. 28 election.

Sharon, 74, appeared to trounce former prime minister Binyamin Netanyahu, the current foreign minister who attacked Sharon during the campaign for being soft on terrorism, according to early projections announced tonight on Israeli television. With about half of the vote counted, Sharon had received 58.6 percent of the ballots cast and Netanyahu about 38 percent.

Netanyahu conceded defeat about three hours before he joined Sharon at a somber victory speech in which the winning candidate asked supporters to forgo election celebrations in the face of the day's deaths and violence.

"This is not a night to celebrate," Sharon said. "We're in the middle of a very difficult campaign, a war against terrorism." He vowed to "hunt down those who have shed the blood of [Israeli] citizens. Nobody has immunity."

According to recent polls, Likud and Sharon are heavy favorites to win in January, when Israel's 5 million voters will cast ballots for a party; the leader of the party that receives the most votes will form a government and serve as prime minister. Israel's other large party, Labor, last week chose as its leader another former army general, Haifa Mayor Amram Mitzna, who advocates reopening peace negotiations with the Palestinians and unilaterally withdrawing Jewish settlements from the West Bank and Gaza.

No one expects Palestinian militants to suspend attacks so Israel can have a peaceful election season, and Sharon, in a news conference broadcast live nationwide about three hours after the attack in Beit Shean -- and with four hours of voting left -- said the aim of the militants was to sow fear and "influence the Israeli election campaign."

"Hundreds of thousands of Israeli citizens today are exercising their democratic rights. Terror is trying to frighten them and keep them at home, to ruin our lives," Sharon said, his voice rising to a shout. "It doesn't matter who you support. Don't allow terror to frighten you. Go and vote! Go and vote!"

In Beit Shean, a middle-class town and Likud stronghold of 17,000 in the Jordan Valley, about six miles north of the West Bank and three miles west of Jordan, Sharon's son Omri, one of his closest advisers and a candidate for a Knesset seat in January, said today's attack was "worse than just murdering someone. They tried to attack our democracy, the basic element of our country."

Police and witnesses said the attack occurred about 3:20 p.m., as about 40 voters and workers were congregated in an open courtyard area in front of the Likud headquarters, a two-story stone building surrounded by apartment houses and small businesses.

Israeli police spokesman Col. Danny Kuffler said two men in a stolen white Mazda pulled up outside the headquarters, jumped out of the car and immediately began firing AK-47 assault rifles at "people standing here to vote."

Witnesses said a security guard stationed in front of the building returned fire as residents of the neighborhood began shouting for help from a local member of the Israeli Border Patrol, Eran David, who was home on vacation.

Kuffler said David ran into the street with his weapon and opened fire on one of the militants, who had just shot the security guard. Israeli soldiers then came running to the scene and also opened fire, and eventually both militants were shot and killed during a battle that lasted three to five minutes. One of the militants was reportedly wearing an explosive belt that did not detonate during the fracas.

Both militants were about 20 feet from the front door of the party headquarters when they were killed.

Among the wounded were the three sons of Israeli legislator and former foreign minister David Levy. "I heard them release the pin of the hand grenade and they said, 'Lie down,' " said Uri Levy, one of the injured brothers. "Then I saw one of them looking at me and he was going to shoot me, but he ran out of bullets. And I shouted at everyone to run away."

The militant al-Aqsa Martyrs Brigades asserted responsibility for the attack in telephone calls to news agencies, saying it was in retaliation for the killings of two militant commanders by Israeli forces in the Jenin refugee camp on Tuesday.

Political analysts were divided about what impact the continuing violence would have on the unfolding election season, a sudden and condensed campaign that was thrust on the country when Labor bolted from Sharon's national unity government on Oct. 30, ultimately causing the government to collapse.

Sharon won the prime minister's office in a landslide in February 2000, promising to improve security. Few people think he has achieved that goal, but he nonetheless remains hugely popular, having cultivated an image of grandfatherly moderation that many opponents don't buy, noting his long history as an iron-fisted soldier and architect of Israel's settlement expansion.

Whether Sharon actually has changed political stripes and become more moderate is one subplot of the campaign. Many pundits say that he longs to ensure his place in history by being the man who finally brings peace to Israel, and that because of his hard-line credentials he has the credibility and stature to negotiate a peace and sell it to the public. Others analysts, however, note his preference for military action over dialogue and say he has no intention of ever seriously negotiating with the Palestinians or compromising to seal a peace pact.

"Sharon in fatigues, an evening suit or a swimsuit is still the same Sharon -- he hasn't changed," said Zeev Sternhell, a left-leaning political scientist at Hebrew University in Jerusalem.

Dani Koren, a Labor supporter and political analyst at Tel Aviv University, said Sharon looks more moderate only in comparison to his challenger, Netanyahu, 53, who was attacking Sharon as a closet liberal for supporting the creation of an independent Palestinian state and for not expelling Palestinian leader Yasser Arafat from his West Bank headquarters to another country.

In the end, however, Netanyahu couldn't sell his message. Political analysts and Likud members said that voters simply found Sharon more reliable and trustworthy, and polls showed he would be the stronger candidate in January.

"Two states [one for Israelis and one for Palestinians] is the only solution for peace," said Shira Simon-Tov, 40, a graphics designer who voted today in Jerusalem. "Sharon finally understands this. Like a wine, he has only improved with age. Netanyahu is more like vinegar and will stay sour."

"Sharon is more experienced, less trigger-happy," said Itzik Mizrahi, 35. "Netanyahu is just a kid, all excitement and bravado."

Anderson reported from Jerusalem.

Prime Minister Ariel Sharon urged Israelis to vote despite a deadly attack by Palestinian gunmen at a polling place in Beit Shean.