CAIRO, Egypt -- On a chilly night, bearded militants gathered at a stage strung with colorful lights in Darna, a Mediterranean coastal city long notorious as Libya's centre for jihadi radicals. With a roaring chant, they pledged their allegiance to the leader of the Islamic State group.

With that meeting 10 days ago, the militants dragged Darna into becoming the first city outside of Iraq and Syria to join the "caliphate" announced by the extremist group. Already, the city has seen religious courts ordering killings in public, floggings of residents accused of violating Shariah law, as well as enforced segregation of male and female students. Opponents of the militants have gone into hiding or fled, terrorized by a string of slayings aimed at silencing them.

The takeover of the city, some 1,000 miles (1,600 kilometres) from the nearest territory controlled by the Islamic State group, offers a revealing look into how the radical group is able to exploit local conditions. A new Islamic State "emir" now leads the city, identified as Mohammed Abdullah, a little-known Yemeni militant sent from Syria known by his nom de guerre Abu al-Baraa el-Azdi, according to several local activists and a former militant from Darna.

A number of leading Islamic State militants came to the city from Iraq and Syria earlier this year and over a few months united most of Darna's multiple but long-divided extremist factions behind them. They paved the way by killing any rivals, including militants, according to local activists, former city council members and a former militant interviewed by The Associated Press. They all spoke on condition of anonymity out of fear for their lives.

Darna could be a model for the group to try to expand elsewhere. Notably, in Lebanon, army troops recently captured a number of militants believed to be planning to seize several villages in the north and proclaim them part of the "caliphate." Around the region, a few militant groups have pledged allegiance to its leader, Iraqi militant Abu Bakr al-Baghdadi. But none hold cohesive territory like those in Darna do.

The vow of allegiance in Darna gives the Islamic State group a foothold in Libya, an oil-rich North African nation whose central government control has collapsed in the chaos since the 2011 ouster and death of longtime dictator Moammar Gadhafi.

Extremists made Darna their stronghold in the 1980s and 1990s during an insurgency against Gadhafi, the city protected by the rugged terrain of the surrounding Green Mountain range in eastern Libya. Darna was the main source of Libyan jihadis and suicide bombers for the insurgency in Iraq after the U.S.-led invasion. Entire brigades of Darna natives fight in Syria's civil war.

This spring, a number of Libyan jihadis with the Islamic State group returned home to Darna. The returnees, known as the Battar Group, formed a new faction called the Shura Council for the Youth of Islam, which began rallying other local militants behind joining the Islamic State group. In September, al-Azdi arrived.

Many of Darna's militants joined, though some didn't. Part of Ansar al-Shariah, one of the country's most powerful Islamic factions, joined while another part rejected it.

The main militant group that refused was the Martyrs of Abu Salem Brigade, once the strongest force in Darna. The fundamentalist group sees itself as a nationalist Libyan force and calls for a democratically formed government, albeit one that must enforce stricter Shariah law.

For the past months, it has battled the al-Battar fighters and the Shura Council. Al-Battar accused the Abu Salem militia of killing one of its top commanders in June and threatened in a statement to "fill the land with (their) graves."

Meanwhile, a militant campaign of killings in Darna targeted the liberal activists who once led sit-ins against them, as well as lawyers and judges. Militants also stormed polling stations, stopping voting in Darna during nationwide elections in March and June.

In July, a former liberal lawmaker in Darna, Farieha el-Berkawi, was gunned down in broad daylight. Her killing in particular chilled the anti-militant movement, said a close friend of el-Berkawi. "People had done their best (to force out militants) and got nothing but more bloodshed," she told the AP.

Those who stayed tried to co-exist. Some submitted letters of "repentance" to the Islamic militias, denouncing their past work in the government. Militant group Facebook pages are dotted with letters of repentance submitted by a traffic police officer, a former militiaman and a former colonel in Gadhafi's security apparatus.

With opposition silenced, militant factions first came together on Oct. 5 and decided to pledge allegiance to al-Baghdadi and form the Islamic State group's "Barqa province," using a traditional name for eastern Libya. After the gathering, more than 60 pickup trucks filled with fighters cruised through the city in a victory parade.

Last week, a second gathering in front of a Darna social club saw a larger array of factions make a more formal pledge of allegiance. Al-Azdi attended the event, according to the former militant. The militant himself did not attend but several of his close relatives who belong to Ansar al-Shariah did.

Now, government buildings in Darna are "Islamic State" offices, according to the activists. Cars carrying the logo of the "Islamic police" roam the city.

Women increasingly wear ultraconservative face veils. Masked men have flogged young men caught drinking alcohol, a former city council member told the AP.

Militants have ordered that male and female students must be segregated at school, and history and geography were removed from the curriculum, according to two activists in the city. New "Islamic police" flyers order clothing stories to cover their mannequins and not display "scandalous women's clothes that cause sedition."

Opposition to the militants, already scattered, is under threat. During the extremists' first meeting, a colleague recounted how Osama al-Mansouri, a lecturer at Darna's Fine Arts college, stood up and asked the bearded men: "What do you want? What are you after?"

Two days later, gunmen shot al-Mansouri dead in his car.