MANILA (Reuters) - Philippine President Rodrigo Duterte on Thursday pleaded for help from mayors in Muslim parts of the south to deal with Islamist militants, and threatened to impose martial law there if the problem is not tackled.

Philippine President Rodrigo Duterte speaks before local town mayors in Davao city in southern Philippines March 9, 2017. REUTERS/Lean Daval Jr

The largely Roman Catholic Philippines has been struggling to thwart two small but violent Islamic State-linked groups behind kidnappings, piracy, bombings and the recent beheading of a German captive.

“I plead before you because I do not want the trouble in (the southern island of) Mindanao to spin out of control,” Duterte told mayors in a speech in Davao.

“Because then, as president, I will be forced, I will be compelled, to exercise the extra-ordinary powers.”

He added: “Help me. If not, you know, martial law, then I have to authorize the military just to arrest them, detain you.”

The Philippines is fighting Abu Sayyaf militants on two remote islands in the south. The government is seeking the support of separatists who are talking peace with the government to root out groups with extremist agendas.

After years of denials by the Philippines that Islamic State is seeking a foothold in the country, Duterte’s administration says it is now certain that local rebels are in contact with Middle East extremists and receiving funds.

Duterte has warned of a “contamination” and the possibility of Islamic State fighters driven from Iraq and Syria taking refuge in the Philippines.

Defense Secretary Delfin Lorenzana said Abu Sayyaf’s kidnappings were a national embarrassment, with the number of hostages increasing to 31 from 18 captives when Duterte came to power on June 30.

“It’s giving me a headache,” he told reporters, adding the military’s deadline to eliminate the militants by June was unrealistic.

“Sometimes, I couldn’t sleep at night.”

He said the army would move an infantry division to Jolo island, an Abu Sayyaf stronghold where most of the captives are held. A marine and naval task force would be deployed to tackle piracy.

Lorenzana said the Philippines would jointly patrol southern seas with Indonesia and Malaysia from April, creating a sea lane for the merchant ships Abu Sayyaf has been intercepting.