MANILA, Philippines — Philippine government forces have foiled an attempt by a few dozen Muslim militants aligned with the Islamic State group to attack a small southern town in fighting that left four gunmen dead, an army official said Wednesday.

Army Lt. Col. Harold Cabunoc said troops clashed with 30-40 militants Tuesday and drove them away from the small farming community of Mopac where they planned to launch an attack on the town center of Datu Paglas about a half kilometer (quarter mile) away.

The militants from the Bangsamoro Islamic Freedom Fighters led by Solaiman Tudon occupied several abandoned houses in Mopac, where he used to live, over the weekend but his family and other villagers asked the gunmen to leave.

"They took sniper positions and placed some bombs in the community and that alarmed the villagers," Cabunoc said.

Troops backed by artillery fire later arrived and clashed with the militants, who fled and were being pursued by government forces, Cabunoc said, adding that villagers started returning to their homes in Mopac on Wednesday.

Tudon's group is one of several small armed militant factions that have expressed support to the Islamic State group.

Clashes have erupted this week in a number of rural villages in Maguindanao province, where Datu Paglas is located, as troops pressed sporadic offensives to prevent a repeat of last year's siege of southern Marawi city by hundreds of Islamic State group-aligned militants. The five-month fighting in Marawi left more than 1,000 combatants and civilians dead and displaced hundreds of thousands of villagers.