Once again, horrific images of dead and injured students flashed across television screens in Pakistan. Once again, sobbing parents rushed into hospitals searching for their children. And once again, Pakistani youths are reminded that they are targets for Islamists seeking to topple a nuclear-armed government.

On Wednesday, a little more than a year after Pakistani Taliban insurgents killed about 150 students and teachers at a school in northwestern Pakistan, militants took new aim at students on track to make up the country’s future professional class.

The attack at Bacha Khan University, which was claimed by a splinter group of the Pakistani Taliban, began shortly after 9 a.m. when four gunmen used the cover of Pakistan’s notorious winter fog to slip onto campus.

The gunmen shot and killed 20 students and two teachers, some execution-style, and wounded nearly two dozen others. Several students said the toll could have been much higher were it not for a teacher armed with a pistol who briefly held off the attackers before being killed.

The massacre in Charsadda, about 30 miles from where the December 2014 school attack occurred in Peshawar, is intensifying fears that Pakistan’s long-term strategy for combating Islamist militant groups is inadequate.

Pakistan’s military says that in the past year it has largely driven groups such as the Taliban and al-Qaeda from the country’s northwestern tribal belt, which became a hub of domestic and international terrorist groups after the 9/11 attacks. But security officials and analysts have warned for months that Pakistan remains vulnerable to major attacks because government leaders have not mounted a widespread offensive against the roots of militancy, including conservative religious seminaries.

“The government says the military operation [against Islamist extremists] is successful,” said Wisal Khan, who said his son, Junaid, was killed in Wednesday’s attack. “But I ask, how can it be that successful if the terrorists are still killing the people and the children?”

The attack is also refocusing attention on the vulnerabilities of schools, both in Pakistan and the West. Schools are generally less well-guarded than government buildings and are tempting targets because “when you hit students and kids, the pain is more,” said Saad Muhammad, a retired Pakistani army general and ­Islamabad-based security analyst.

“Terrorists hate” schools, Muhammad added, “because they say this is Western education and it’s un-Islamic.”

But it appears that the carnage at Bacha Khan University, named after a late Pashtun nationalist and inspirational force behind the founding of the progressive Awami National Party, could have been worse.

After the Pakistan Taliban attacked the army-run school in Peshawar in 2014, officials began allowing some teachers to carry weapons in the classroom and gave them weapons training.

Syed Hamid Husain, an assistant chemistry professor at Bacha Khan University, was apparently carrying his pistol Wednesday when the gunmen sneaked onto campus.

In separate interviews with Agence France-Presse and The Washington Post, several students described Husain as a hero because he pulled out his pistol and confronted the attackers, who were armed with assault rifles. The 27-year-old teacher was killed in the ensuing exchange of fire.

Students said Husain’s actions gave them time to hide or escape.

“We saw the professor standing there with a gun in his hand,” said Shaid Malik, 22, a geology student. “He told us to rush back to our rooms and do not open the door for anyone.

“When the firing stopped, after a while, we came down and saw the professor dead, lying on the ground with the same gun in his hand.”

Another student, Mohammad Shabeer, said Husain held off the attackers for 15 minutes before he was killed.

Shabeer said another student, who also was armed because of threats that had been made against him and his family, helped Husain battle the attackers.

That student also was killed, he said.

A spokesman for the Pakistani military was not able to confirm the students’ version of events. But one school official said the presence of armed security guards on campus had been instrumental in averting a far greater death toll.

The guards battled the attackers before police and paramilitary forces arrived, which kept the gunmen from entering the women’s dormitory, the official said.

Maj. Gen. Asim Bajwa, a spokesman for the Pakistani military, said investigators are trying to determine the nationalities of the gunmen and who supplied them with weapons.

A Pakistani Taliban regional group — led by Omar Mansour from the Darra Adamkhel region — sent a statement to reporters Wednesday claiming responsibility. Mansour is also believed to have been a mastermind behind the Peshawar school attack.

But highlighting an emerging split within the group, the main Pakistani Taliban faction issued a separate statement denouncing the killings as “un-Islamic.”

The Pakistani Taliban, an offshoot of the Taliban group waging an insurgency in Afghanistan, is pushing for the imposition of sharia law in Pakistan. Since its founding in the mid-2000s, more than 50,000 Pakistanis have been killed in terrorist attacks or battles between the military and Islamist militants.

The military operation against the group began in June 2014 after an attack on Karachi’s international airport killed more than two dozen people. Since then, especially over the past year, there has been a major decline in terrorist attacks in Pakistan.

But analysts said militant groups still have a plentiful pool of potential recruits, both in conservative rural areas and relatively modern major cities. Pakistani leaders have also been slow to arrest radical clerics who coddle Islamist extremists, analysts say.

“This attack clearly shows that terrorists have not disappeared from Pakistan. Although they are weakened, they are there,” said Hassan Askari Rizvi, a local security analyst. “And their motive is clear: They want to tell everyone they are kicking and alive.”

Aamir Iqbal and Haq Nawaz Khan in Charsadda and Shaiq Hussain in Islamabad contributed to this report.

Read more:

The key to solving the puzzle of Afghanistan is Pakistan

After years of tension, anti-American sentiment ebbs in Pakistan

Today's coverage from Post correspondents around the world