The Philippine president has threatened to impose martial law nationwide to combat a serious threat in the southern region of Mindanao after fighters there beheaded a police officer and took churchgoers hostage.

The ongoing violence has forced thousands to flee the city of Marawi, located about 816km south of the capital Manila.

"I will not hesitate to do anything and everything to protect and preserve the Filipino nation," Rodrigo Duterte said on Wednesday after arriving back in Manila from his trip to Russia.

READ MORE: Children and Duterte's drug war - Lessons from the past

"I might declare martial law throughout the country to protect the people."

Duterte declared martial law on Tuesday in Mindanao - which makes up roughly one-third of the Philippines and is home to 20 million people - in an immediate response to the attacks by the fighters.

The military claimed to have killed at least 13 fighters, members of groups that have pledged allegiance to the Islamic State of Iraq and the Levant (ISIL, known as ISIS) group.

The roughly 100 attackers roamed through Marawi, killing five soldiers, taking a priest and an unspecified number of other people hostage from a church, setting fire to buildings and flying black ISIL flags, according to Duterte and his aides.

Duterte said the fighters beheaded the local police chief after capturing him at a road checkpoint.

Local television station GMA News also published exclusive images of nine civilians, who were reportedly killed by the armed fighters.

ABS-CBN television channel also quoted the interior ministry as saying that the fighters managed to take control of the city jail and freed 107 prisoners.

The violence first erupted on Tuesday after the army raided the hideout of Isnilon Hapilon, a commander of the Abu Sayyaf group.

Abu Sayyaf then called for reinforcements from an allied group, the Maute, and dozens of fighters managed to enter Marawi, home to about 200,000 people.

In ensuing clashes with the attackers, security personnel lost three of their comrades.

The attackers reportedly burned a Catholic church, the city jail, and two schools, as well as occupied the main streets and two bridges leading to Marawi.

READ MORE: Peace is still possible in Duterte's Philippines

Archbishop Socrates Villegas, president of the Catholic Bishops Conference of the Philippines, said the fighters forced their way into the Marawi Cathedral and seized a priest, 10 worshippers and three church workers.

"They have threatened to kill the hostages if the government forces unleashed against them are not recalled," Villegas said in a statement.

"[The priest] was not a combatant. He was not bearing arms. He was a threat to none. His capture and that of his companions violates every norm of civilised conflict."

Al Jazeera's Jamela Alindogan, reporting from Mindanao on Wednesday, said there is an exodus of thousands of residents from Marawi.

"People have been walking for hours to try to escape the violence and get out of a city that was once the most peaceful in the southern Philippines," she said.

Abu Sayyaf and Maute have been blamed for bombings, attacks against government forces and kidnappings. They have also beheaded hostages.

Mindanao emergency

Tuesday's emergency declaration of the military rule in Mindanao took immediate effect and will last for 60 days, according to Ernesto Abella, Duterte's spokesperson, said from Russia, where Duterte was on a scheduled four-day official visit.

"This is possible on the grounds of the existence of rebellion," Abella said.

Duterte had earlier hinted declaring martial law in Mindanao on May 19, saying: "If I declare martial law in Mindanao, I will solve all that ails the island."

READ MORE: Inside Abu Sayyaf - Blood, drugs and conspiracies

Steven Rood, of the Asia Foundation, said there are several restrictions under the country's current post-dictatorship constitution.

"There is a time limit of 60 days, the courts continue to operate, the legislature is still there - so there has been an attempt to soften the effects of martial law," he told Al Jazeera from Manila.

"On the other hand, the persisting violence in Mindanao hasn't been soft, and so particularly strong-willed people such as the president often think of something forceful like martial law."