Duterte said the presence of foreign fighters in street battles that have raged since Tuesday in Marawi City was proof that ISIS had gained a foothold on the restive island of Mindanao, but there was still a chance for peace.
"You can say that the ISIS is here already," Duterte told soldiers in nearby Iligan City.
"My message mainly to the terrorists on the other side is we can still solve this through dialogue. And if you cannot be convinced to stop fighting, so be it. Let's just fight."
Special forces commandoes were deployed to drive out the remaining 20 to 30 Maute group rebels holed-up in Marawi but encountered heavy resistance on Friday. The army said 11 soldiers and 31 militants have been killed.
Fighting erupted on Tuesday after a bungled raid by security forces on a Maute hideout, which spiralled into chaos, with gunmen seizing bridges, roads and buildings and taking Christians hostage. Duterte responded by declaring martial law throughout his native island of Mindanao.
Rohan Gunaratna, a Singapore-based security expert, said the siege was a wake-up call for the Philippines.
"ISIS capturing a major city in the Philippines is a very significant blow to the security and stability of this region," he said.
"The Filipinos need to get their act together ... They must understand the truth that ISIS ideology took hold in their country. The local groups have transformed."
Malaysians, Indonesians and other foreigners were among the guerrillas killed on Thursday, which the government said demonstrated how the Philippines could become a haven for overseas terrorists.
The White House on Thursday said it backed the Philippine fight against "cowardly terrorists".
Duterte has warned of "contamination" by ISIS, exploiting the poverty, lawlessness and porous borders of predominantly Muslim Mindanao island to establish a base for radicals from Southeast Asia and beyond.
He has pleaded with political and Islamic leaders to keep foreign and local terrorists at bay. Months of air and ground offensives in Mindanao have not dented their resolve.
"What's happening in Mindanao is no longer a rebellion of Filipino citizens," Solicitor General Jose Calida told reporters in explaining why martial law was imposed.
Most of Marawi's 200,000 inhabitants fled after the gunmen ran amok on Tuesday, seizing and torching buildings, freeing militants from jails and taking a priest and churchgoers hostage at the city's cathedral.Duterte has dealt with separatist unrest during his 22 years as mayor in Mindanao but the Maute's rise and signs that it has ties to another group, the Abu Sayyaf, present one of the biggest challenges of a presidency won on promises to fight drugs and lawlessness.
Philippine intelligence indicates the two groups from different parts of Mindanao are connected, through Isnilon Hapilon, a leader of a radical faction of Abu Sayyaf.
Abu Sayyaf has a track record of banditry, piracy and violence, while the lesser-known Maute group has proven itself a fierce battlefield opponent for the military, able to sustain air and artillery bombardments and regroup after heavy losses.
Hapilon was the target of Tuesday's botched raid and Duterte said ISIS in the Middle East had anointed him as its man in the Philippines, and Hapilon was revered as its leader.
Military chief General Eduardo Ano said the fierce resistance by the Maute in Marawi was to protect Hapilon, who was in poor condition after being wounded in a January air strike.
"If we capture him, all the better. But if he fights back we have to do what is necessary," he told reporters.
Convoys of vehicles packed with evacuees and protected by soldiers streamed into Iligan. Mark Angelou Siega, a Christian, described how students fled their campus.
"We were so scared and so were our Muslim brothers and sisters. We were sure they would get to us," he said.
"These terrorists are not real Muslims."
Calida said the Maute group and ISIS were radicalising young Muslims and the government was not the only target of their aggression.
"People they consider as infidels, whether Christians or Muslims, are also targets," he said.
(Additional reporting by Neil Jerome Morales in DAVAO CITY, Kanupriya Kapoor in SINGAPORE, Romeo Ranoco in MARAWI CITY and Enrico dela Cruz and Manolo Serapio Jr in MANILA; Writing by Martin Petty)