Philippine President Rodrigo Duterte has declared martial rule in the country's south for 60 days to deal with with an attack by Muslim extremists allied with the Islamic State group who laid siege to a southern city.
Presidential spokesman Ernesto Abella told reporters in Moscow that the martial law took effect on Tuesday evening, and Mr Duterte will cut short a trip to Russia to return home.
Defence secretary Delfin Lorenzana said troops raided the hideout of a leading terrorist suspect in southern Marawi city, sparking a gun battle that prompted the militants to call for reinforcements.
Officials said the gunmen occupied the city hall, a hospital and a jail and burned several houses in a daring attack.
At least two soldiers and a police officer were killed and 12 others wounded in the incident.
Several militants were also killed in the fighting in the city in Lanao del Sur province, about 830 kilometres (520 miles) south of Manila.
However, others continued to lay siege to the largely Muslim city of more than 200,000 people, officials said, adding that power was cut in the city in a chaotic scene.
Philippine foreign secretary Alan Peter Cayetano said he informed his Russian counterpart Sergey Lavrov of Mr Duterte's decision to fly home early to deal with the crisis.
Mr Cayetano said he would stay behind in Moscow, where a number of agreements are to be signed between the governments.
Mr Duterte's martial law declaration will help government forces carry out searches and arrests and detain rebel suspects more quickly, Mr Lorenzana said.
He said offensives would also be staged in other southern provinces plagued by extremist groups.
Despite the moves, he said the government remains in control of the situation in Marawi city and other security trouble spots in the south.
Military chief of staff General Eduardo Ano said the fighting broke out in Marawi when troops attacked a hideout for Muslim extremist leader Isnilon Hapilon.
Hapilon reportedly has been chosen to lead an Islamic State group branch in south-east Asia and is on the US Department of Justice list of most-wanted terrorists worldwide, with a reward of up to five million US dollars (£3.8 million) for his capture.
An Arabic-speaking Islamic preacher known for his expertise in commando assaults, he pledged allegiance to the IS group in 2014, according to security officials.
Mr Ano said Hapilon, who is still recovering from wounds sustained in a military air strike in January, and more than a dozen of his men summoned reinforcements from their allies in the Maute militant group.
He said nearly 50 gunmen in all managed to enter the city.
One group of about 20 gunmen took position in a hospital, where they raised a black Islamic State group-style flag at the gate, and 10 other militants went near a provincial jail where troops and policemen engaged them in fighting, he said.
Troops sealed off major entry and exit points to prevent Hapilon from escaping, Mr Ano told The Associated Press by telephone from Moscow, where he was accompanying Mr Duterte.
"They did some burnings, they showed up in another area so it looked chaotic, but it's actually a small group facing an overwhelming number of government forces," Mr Ano said.
"We will conduct house-to-house clearing and do everything to remove the threat there. We can do that easily," he said, but added it was more difficult in an urban setting because of the need to avoid civilian casualties.
The Maute group is one of less than a dozen new armed Muslim groups that have pledged allegiance to IS and formed a loose alliance in the southern Philippines in recent years.
Hapilon was reportedly designated the leader of the alliance.
Mr Duterte had repeatedly threatened to place the south, the scene of decades-long Muslim uprisings, under martial law if terrorism spiralled out of control.
Human rights groups have expressed fears that martial law powers could further embolden Mr Duterte, whom they have accused of allowing extrajudicial killings of thousands of drug suspects in a crackdown on illegal drugs.