A Palestinian man fatally stabbed two Israeli men during prayers in Tel Aviv on Thursday, while three people — including an 18-year-old American volunteer — were killed later Thursday in a separate attack in the West Bank.

The American was identified in media reports as Ezra Schwartz, of Sharon, Mass., a yeshiva student in Beit Shemesh near Jerusalem. He had been delivering food to patrolling soldiers at the time of the attack.

The two worshipers killed in Tel Aviv were attacked on the second floor of the Panorama office building where a group of Israelis had gathered to hold afternoon prayers.

Shimon Vaknin, a witness, said a bloodied man stumbled into their prayer room.

“In the middle of the prayers, suddenly we saw a man fall down wounded at the entrance to the synagogue and behind him a man with a knife who was trying to get inside,” Vaknin told the Times of Israel. “Someone shouted, ‘There’s a terrorist!’”

Some of the men tended to the victim while the rest slammed shut the doors to the room, he said.

“We managed to close the doors and he tried to force them open. If he would have managed to get inside, he would have slaughtered the worshipers,” he said. “We used all of our strength to not let him inside and then he went on to the nearby shops to try and hurt someone there.”

After grabbing some makeshift weapons, the men went after the attacker before they discovered the other wounded victim sprawled on the floor.

The two dead men were identified as Aharon Yesayev, 32, and Reuven Aviram, 51, Haaretz reported. A third Israeli was moderately wounded.

The assailant, who was caught by civilians, was identified as Riad Mahmoud al-Masalma, 36, a father of five from the West Bank village of Dura, the paper reported.

Masalma, who recently obtained a permit to work in a Tel Aviv eatery, told investigators he entered Israel to kill Jews, Haaretz reported.

The Hamas terror group hailed the attack.

“We welcome the heroic operation in Tel Aviv that killed two people,” read a tweet on the Gaza-based group’s official account. “We call on the Palestinians to continue such activities.”

In the West Bank attack, three people were killed when a Palestinian fired an Uzi submachine gun at cars stuck in a traffic jam near the Gush Etzion junction in the West Bank, The Jerusalem Post reported.

The gunman was shot by security forces and arrested after he left his vehicle and tried to fire additional shots.

In addition to Schwartz, the dead victims were identified as Yaakov Don, 51, of nearby Alon Shvut, and Shadi Arafa, a Palestinian who was a passenger in one of the vehicles targeted by the gunman, according to Israeli media.

Several others were wounded in the attack, including other Americans studying at a yeshiva in Beit Shemesh, according to reports.

Palestinian media identified the assailant as 24-year-old Mohammed Abdel Basset al-Kharoub, from the West Bank village of Dir Smat near Hebron.

Yuval Lasri, who overpowered the terrorist, told Ynetnews: “I stood in the traffic jam and heard gunfire. The terrorist rammed a car behind me. I got out of my car, pushed his gun away and threw him on the ground. I didn’t shoot at him because I wasn’t sure that he was the terrorist, but then I saw the gun next to him and understood that he was.”

Thursday’s violence brings the number of Israelis killed in the wave of violence to 16. At least 82 Palestinians have been killed by Israeli fire, 52 of them said by Israel to be attackers, the remainder killed in clashes with Israeli troops.