MANILA, June 21 (Reuters) - Islamist militants who stormed a primary school in a southern Philippines town on Wednesday have fled, leaving behind 31 hostages unharmed, including 12 children, a spokesman for the military said.

"The enemy made a hasty withdrawal, leaving behind 31 hostages, among them 12 youngsters," Brigadier General Restituto Padilla told Reuters.

Padilla said troops have cordoned off the school because the militants had planted improvised explosive devices around the area.

He said troops were pursuing the militants, who are members of the Bangsamoro Islamic Freedom Fighters.

(Reporting by Manolo Serapio Jr.; Editing by Raju Gopalakrishnan) ((manolo.serapio@tr.com; +632 841 8972; Reuters Messaging: manolo.serapio.thomsonreuters.com@reuters.net Twitter: @MannySerapio))