KABUL, Afghanistan — They looked like Afghan Army soldiers returning from the front lines, carrying the bodies of wounded comrades as part of the ruse.

Dressed in military uniforms, a squad of 10 Taliban militants drove in two army Ford Ranger trucks past seven checkpoints. They arrived inside northern Afghanistan’s largest military installation just as hundreds, perhaps thousands, of unarmed soldiers were emerging from Friday Prayers and preparing for lunch.

For the next five hours, the militants went on a rampage, killing at least 140 soldiers and officers in what is emerging as the single deadliest known attack on an Afghan military base in the country’s 16-year war. Some assailants blew themselves up among the soldiers fleeing for their lives, according to survivors, witnesses and officials.

“Today, there was even a shortage of coffins,” said Ibrahim Khairandish, a member of the provincial council in Balkh Province, where the attack took place. Other officials feared that the death toll could exceed 200.