Eight people were killed last night and nine more wounded - three critically - when a terrorist gained entrance to the Mercaz Harav yeshiva in Jerusalem's Kiryat Moshe neighborhood and opened fire inside the yeshiva's library.

The gunman, apparently an East Jerusalem resident from the Jebel Mukaber neighborhood, was shot and killed.

An organization calling itself Galilee Freedom Battalions-the Martyrs of Imad Mughniyeh claimed responsibility for the attack, according to Hezbollah's Al-Manar television station. The claim could not be verified.

The Galilee Freedom Battalions has claimed responsibility for a number of terror attacks in recent years but there is no definitive proof that the organization actually exists.

Hezbollah did not make an official statement claiming responsibility for the incident although individuals associated with the organization told the BBC yesterday that the organization intends to carry out further responses to the killing last month in Damascus of its terror chief, Imad Mughniyeh.

Witnesses said the terrorist walked into the yeshiva, apparently concealing a gun in a box, and went into the library. He fired at the occupants and then entered the auditorium, where he fired at the two students inside.

Yitzhak Danon, a student at the yeshiva, told Channel 2 television that he fired two shots into the attacker's head, after which an IDF paratrooper who lives nearby killed the gunman. Two police detectives who arrived on the scene also fired at the terrorist.

"I was outside the library. I heard explosions and shots in the library and went up to the roof, one half-floor below the library," Danon related.

"I laid down, cocked my gun and waited. There were shots in the library the whole time. The terrorist went out for a moment and I saw he had a Kalashnikov. I couldn't shoot him in time and he went back in. I waited and he went out again and I fired two shots into his head. He swayed back and forth."

Another witness, Michael Stetner, who was scheduled to play music at the yeshiva last night, said he heard automatic-rifle fire that continued for about 10 minutes. "Five hundred or 600 bullets were fired. I saw just one terrorist."

Witnesses said about 80 people were gathered in the library.

A large number of security and emergency medical personnel arrived on the scene, with some 50 ambulances summoned. Police and IDF soldiers searched the yeshiva complex and its environs looking for a second or even a third terrorist before they determined the terrorist acted alone.

Three of the injured taken to Hadassah Medical Center Ein Karem in critical condition; six people with minor injuries were taken to Sha'arei Tzedek Medical Center. One of the wounded is 15 years old.

Prime Minister Ehud Olmert called the attack "a serious event. It shows the extent to which the Palestinian Authority is insufficiently fighting terror. We will not make our peace with such events."

Olmert told associates that there is a direct link between terror elements in Gaza and those in the West Bank, and between the firing of rockets at the Negev and the terror attack in Jerusalem. "It's the same people with the same motives," Olmert said.

After hearing reports of Torah scrolls riddled with bullet holes and prayer shawls covered in blood, Olmert said: "It only shows the kind of people we are up against."

The prime minister was particularly angered after seeing news footage showing people in Gaza celebrating the attacks. "It's another moral low that the Palestinians have reached. They go out dancing when boys are murdered in cold blood here."

Olmert was returning from Jerusalem after military consultations in Tel Aviv when he heard the news. He spoke with Defense Minister Ehud Barak, Public Security Minister Avi Dichter and Foreign Minister Tzipi Livni, as well as Jerusalem Mayor Uri Lupoliansky.

After the attack, Livni called her American counterpart, Condoleezza Rice, European Union foreign affairs chief Javier Solana, United Nations Secretary Ban Ki-Moon and the foreign ministers of Russia, Britain and Germany to express Israel's protest. MK Benny Elon, chairman of the National Union, and a Mercaz Harav graduate, said he was praying that the school's students and leaders had the strength to cope with the loss.

MK Uri Ariel, chairman of the National Union-National Religious Party Knesset faction, said: "The vicious slaughter in the main yeshiva of the national religious movement did not take place in a vacuum. A government that negotiates on the division of Jerusalem, enables the movement of armed terrorists in Samaria and does not destroy terror is responsible for allowing this horrific night to take place. No showcase military operation could replace the fundamental work needed to root out terror," he said.

NRP chairman MK Zevulun Orlev said: "It is not for naught that the base murderers chose to carry out their bloodbath in the very heart of the religious Zionist movement. The terrible slaughter at Mercaz Harav is the price of Israeli hesitance in the war against Hamas. Those who demonstrate weakness in the face of terror in Gaza pay the price in Jerusalem as well."

MK Aryeh Eldad (National Union) said: "The murder in the heart of Jerusalem is the lesson learned by the Arabs from the hesitancy shown by the government in light of the constant strikes in the South and the willingness of Ehud Olmert and Tzipi Livni to continue their frenzied dance to create a terror state in the heart of Jerusalem and the heart of Israel. The current government represents an existential danger to the State of Israel," Eldad said.

PA President Mahmoud Abbas denounced the attack, stressing that he opposed all actions aimed at hurting civilians, whether Israeli or Palestinian.

But in Gaza, Hamas welcomed the terrorist attack. "We bless the [Jerusalem] operation. It will not be the last," Hamas said in a statement. In Gaza City, residents went into the streets and fired rifles in celebration.

Israeli military sources said the choice of a yeshiva as a terrorist target was not significant. The Shin Bet security service was aware that terror organizations were trying to carry out attacks but had no concrete intelligence about specific plans.

About six weeks ago, two men armed with a pistol and a knife entered the Mekor Haim Yeshiva in Gush Etzion. They were shot and killed by a staff member.

(Jonathan Lis, Yair Ettinger, Amos Harel, Yuval Azoulay, Anshel Pfeffer, Shahar Ilan, Nadav Shragai and Yoav Stern all contributed to this report.)