Police gunned down machete-wielding militants who stormed security outposts in Thailand's (search) Muslim-dominated south Wednesday, killing at least 112 people in one of the bloodiest days in the Southeast Asian kingdom.

The attackers were mostly teenagers — some wearing red headbands — intent on stealing guns. They were poorly armed and overwhelmed by police, who had been tipped off in advance and were lying in wait for them. Officials said 107 militants and five security personnel were killed.

In Bangkok, a somber but resolute Prime Minister Thaksin Shinawatra (search) said the shootings would help halt a simmering, decades-old Islamic separatist struggle in the mainly Buddhist (search) nation.

"It will be hard for them to do these kinds of bad things again," Thaksin said, promising to round up those who masterminded the attacks.

The eight hours of mayhem ended when police fired tear gas and rocket-propelled grenades into a 16th century mosque, killing 32 militants who had taken shelter inside after fleeing an earlier battle.

Mangled bodies were piled inside the cramped red-brick mosque, filled with the lingering, acrid smell of tear gas. Some were dressed in traditional sarongs, others in trousers.

No group claimed responsibility for the highly coordinated assault by possibly hundreds of militants, although past violence has been blamed on separatists seeking to carve a Muslim homeland in the south.

"Whoever these people were, they have shown ... that they are willing to die, simply to fight against Buddhist officials or central government authorities. This is very dangerous," said Sunai Phasuk, a Bangkok political analyst.

"They fought with knives and swords, fully understanding that the police will be ready and waiting for them with M-16 rifles ... they refused to back off," he said.

Army chief Gen. Chaiyasith Shinawatra said 17 insurgents were arrested. He said three policemen and two soldiers were killed and 15 policemen wounded.

The extent of Wednesday's bloodshed rivals that of pro-democracy uprisings crushed by the military in 1973, 1976 and 1991 — respectively leaving 71, 41 and 40 dead, according to official counts that many believe are understated.

Thaksin linked the raids to a Jan. 4 attack on a military camp in the nearby province of Narathiwat, which triggered an upsurge of violence in the area. Four soldiers were killed and hundreds of guns stolen in that raid.

"The masterminds of this movement were in such high spirits after they raided the army camp, and they believed that they could do it again. But they were wrong," Thaksin said.

He also said the separatist struggle had been reignited with money from drug traffickers and corrupt politicians — and not international terrorists.

The violence erupted before dawn when the insurgents attacked more than 15 police bases, village defense posts and district offices in Yala, Pattani and Songkhla provinces in a bid to steal weapons.

Lt. Gen. Proong Bunphandung, police chief for the south, said some of the attackers had guns but most carried only machetes.

"The security officers have been patiently working with local people and gathering intelligence. We waited for the right time to achieve this success," he said.

Many parts of the region have been under martial law for months. Security was tightened Wednesday along the border with neighboring Malaysia, which has in the past denied allegations of harboring militants.

Thaksin said the attackers arrived at the target point with brand new motorcycles. "This proves they got financial support from influential figures, including politicians and drug gangsters," he said, without elaborating.

The shooting shocked residents and local leaders in the south.

Muslims have long complained of discrimination in jobs and education in Pattani, Yala and Narathiwat — Thailand's only Muslim-majority provinces.

They also say their culture and language are being subjugated by the Buddhist Thais, and cite as an example the state schools, which teach in Thai language. Muslims in the south speak Yawi, a dialect of Malay, spoken in neighboring Malaysia.

The alienation caused by the central government's policies has been the source of a decades-old separatist struggle, which had subsided after an amnesty in the late 1980s before exploding into a frenzy of violence with the army arsenal raid in January.