Taliban members cut their way through a fence in the campus perimeter to gain access to the students and faculty. Some victims were shot as they fled, and others were rounded up to be executed. Four of the suspected attackers were killed by security forces.

ISLAMABAD, Pakistan — Gunmen slipped into a college campus under cover of fog Wednesday, killing at least 20 people — some shot execution style — in the latest terrorist attack in Pakistan targeting students in apparent revenge for expanding military crackdowns.

The attack, claimed by a Taliban faction, is likely to unite the country behind stern action against Islamist militant groups 13 months after a similar rampage on a nearby army-run school killed about 150 students and teachers.

Four suspected attackers also were killed in Wednesday’s bloodshed, officials said.

Pakistan Prime Minister Nawaz Sharif vowed a “ruthless response,” saying the attack was on all of Pakistan.

“Cowards and their finances will see our national resolve to eliminate terror,” a statement issued by his office said, even as some Pakistani media outlets reported that the death toll could rise from among the dozens wounded.

The assault began about 9 a.m. when at least four gunmen cut through a back fence into Bacha Khan University in Charsadda, about 30 miles from Peshawar.

“I saw two terrorists standing on the roof . . . They were shouting Allahu Akhbar,” said Basit Khan, a student of computer sciences, referring to an Islamic cry for God is great. “After that, firing started and I and my friends started running. There were people screaming. We were terrified.”