JALALABAD, Afghanistan — A nearly seven-hour assault by extremists on a school for midwives in eastern Afghanistan killed two people and wounded 11 others, but at the end of a harrowing day, the authorities managed to avert a far greater tragedy.

Most of the 67 young female students were evacuated quickly or fled to a fortified safe room on the grounds of the school in Jalalabad. Three of them were wounded, according to a police official. In addition, 12 young children in a day care center for the school’s staff escaped harm, the authorities said.

Gholam Sanayi Stanikzai, the police chief for Nangarhar Province, said the attack ended after two suicide attackers, who had been fighting with automatic weapons and grenades, detonated their explosive vests as the police closed in.

Two male employees of the center were killed and five others wounded, he said, and three police officers were wounded, as well. All the students and the children were rescued.