Hamas forces storm the mosque in the southern town of Rafah after its imam, guarded by gunmen, declares that his militant group will impose an Islamic state. Sixteen people are reportedly killed.

JERUSALEM AND GAZA CITY — Hamas government forces stormed a mosque in the Gaza Strip on Friday and apparently subdued a heavily armed group of Al Qaeda-inspired militants whose imam had vowed to impose theocratic rule in the Palestinian territory.

Sixteen people were reported killed in fighting that raged for much of the day in the city of Rafah.

Residents contacted by telephone said it took Hamas six hours to capture the two-story mosque from a group calling itself Jund Ansar Allah, or the Soldiers of the Companions of God. Fighting spread to the nearby home of the imam, who had fled the mosque, and ended early today after an explosion demolished part of the house, witnesses said.

Medical officials said combatants on both sides were killed, along with some civilians, including a child caught in the crossfire of machine guns and rocket-propelled grenades. At least 120 people were reported wounded.

The whereabouts of the imam, Abdel-Latif Moussa, was unclear.

Gaza's interior ministry announced at 2 a.m. that its forces had regained full control of Rafah from what a Hamas spokesman, Sami abu Zuhri, called outlaws led by a "mentally disturbed" cleric. The southern city remained under curfew.

Moussa, a 60-year-old Palestinian physician sporting a thick beard and red robe, triggered the confrontation with a defiant sermon and display of weapons at midday prayers. Surrounded by four black-clad men with assault rifles, he declared that his group would make Gaza an Islamic "emirate" by force of arms.

Witnesses said several hundred followers filled the mosque with shouts of approval. Al Qaeda uses the term "emirate" to mean a state of clerical rule across the Islamic world. Hamas forces later ringed the mosque and demanded the surrender of the imam and his gunmen.

Rafah, along the Gaza-Egypt border, is a stronghold of Salafist groups that claim inspiration from Al Qaeda and pose a growing challenge to Hamas, which they consider too liberal. Their numerical strength and links to Al Qaeda are unclear.

Hamas itself is an armed Islamic movement with ties to Iran and Syria. But it defines its cause as a nationalist struggle against Israel, not global jihad against the West.

Despite scattered efforts by members of Hamas to impose dress codes on Gaza's Mediterranean beaches and in other public places, its leaders have resisted Salafist demands to put Gaza under rigid fundamentalist rule. Jund Ansar Allah has threatened to burn down Internet cafes, which are popular among the enclave's 1.5 million people.

The imam's uprising was the strongest internal challenge to Gaza's rulers since 2007, when Hamas gunmen ousted security forces of the U.S.-backed secular Fatah movement that had long dominated Palestinian politics.

In the winter, Hamas survived a 22-day assault on Gaza by Israeli forces that in effect halted years of rocket attacks by the group against Israeli communities across the border. Hamas' adherence to a cease-fire is under criticism from smaller militant groups.

The first challenge from Jund Ansar Allah came in June when the group claimed responsibility for an attack by militants on an Israeli military base on the Gaza border. Three of the attackers, who were on horseback, were killed.