The Philippines army has said two coast guard personnel kidnapped and held hostage by Islamic militant group Abu Sayyaf managed to escape during a raid.
The two men fled the jungle camp in the southern province of Sulu on Wednesday night during the two-hour gun battle.
The army had attacked the camp to free them and other hostages.
Abu Sayyaf, a small but violent group known for carrying out kidnappings for ransom, aims to establish an independent Islamic state in the south.
One of the hostages, Rod Pagaling, told the Associated Press: "When gunfire rang out as close as 15m from us, I thought it was my opportunity to survive so I ran away in the confusion."
Brig Gen Alan Arrojado told AP that Mr Pagaling and the other hostage, Gringo Villaluz, told him the militants "panicked and fled in different directions after seeing that the army had come so close and had begun the assault".
The two men sprinted through the forest and later found help at a nearby village. They only found out about each other's escape when they saw each other at a hospital on Thursday, reported AFP.
Up to 15 Abu Sayyaf militants died, while the military had no casualties.
The men were kidnapped in May in the southern city of Dapitan along with a village official, and later transported to the jungle camp.
The militants beheaded the village official last week and threatened to kill the coast guard men next, after the Philippines government rejected the group's ransom demand.
The Abu Sayyaf is holding a number of hostages in various camps in the south of the Philippines, including Malaysians and a Dutchman.
Militants freed a Swiss hostage in December.