A 14-year-old student of the religious school was also injured in the attack at Shehzad town area of Islamabad, police said.
The gunmen fled after the shooting spree, media reports said.
The police said the gunmen sprayed bullets at the school and seriously injured teacher named Qari Arif and another man identified as Darwesh, who both died later in the hospital.