In Gaza, the Islamic militant Hamas praised the attack but stopped short of claiming responsibility. Thousands poured into the streets to celebrate, firing rifles in the air.
"We bless the (Jerusalem) operation. It will not be the last," Hamas said in a text message sent to reporters.
In Lebanon, Hezbollah's Al-Manar television said a previously unknown group called the Martyrs of Imad Mughniyeh and Gaza claimed responsibility for the attack.
Mughniyeh, a top Hezbollah commander, was killed Feb. 12 by a car bomb in Syria. Hezbollah blamed his assassination on Israel, which denied any role.
The attack in Jerusalem came a day after Secretary of State Condoleezza Rice persuaded moderate Palestinian President Mahmoud Abbas to return to peace talks with Israel and on the same day Egyptian officials were trying to mediate a truce between Gaza militants and Israel.
Abbas suspended the talks after Israel launched a military offensive against Gaza militants barraging southern Israel with rockets. Palestinian officials say more than 120 were killed in Gaza during the weeklong operation. Four Israelis were also killed.
Yitzhak Dadon, a seminary student, said he was armed with a rifle and waited on the roof of a nearby building during the attack.
"He came out of the library spraying automatic fire. ... The terrorist came to the entrance and I shot him twice in the head," he said.
Medic Yaron Tzuker said he arrived as the gunfire was still going on.
"They were still shooting when we got here," he told Channel 10 TV. "We took cover and the ambulance was hit. It's horrible inside -- dead bodies and wounded -- it's horrific."
Another witness told Israel TV that he heard both single shots and automatic gunfire from inside the building, and it lasted for about 10 minutes.
Jerusalem police spokesman Shmuel Ben Ruby said one of the gunmen who attacked the seminary was wearing what at first appeared to be an explosives vest but turned out to be a belt holding extra ammunition.
"One or two terrorists infiltrated the Mercaz Harav seminary and opened fire in all directions," the police spokesman said. "One terrorist was killed in an exchange of fire, and apparently he had an explosives belt."
Hundreds of police surrounded the area and searched the campus as ambulances raced to the scene. Scores of seminary students spilled out onto the sidewalk and street outside after they were evacuated.
"There are at least seven killed and 10 people wounded," said Eli Dein, director of Israel's rescue service.
An hour after the attack, medics began removing the dead from the building, taking them away in ambulances.
The seminar is the Mercaz Harav yeshiva in the Kiryat Moshe quarter at the entrance of Jerusalem, a well-known center of Jewish studies identified with the leadership of the Jewish settlement movement in the West Bank.
There were no attacks by Palestinian militants in Jerusalem during 2007, though police and the military claimed to have foiled many attempts. Between 2001 and 2004, at the height of Palestinian-Israeli fighting, Jerusalem was a frequent target of Palestinian attacks, including suicide bombings on buses.
"It's very sad tonight in Jerusalem. Many people were killed in the heart of Jerusalem," Jerusalem Mayor Uri Lupolianski.
Earlier Thursday, Palestinian militants in Gaza set off a bomb on the Gaza border, blowing up an Israeli army jeep and killing a soldier.