LONDON — Libyan fighters declared victory over the Islamic State at its coastal stronghold of Surt on Tuesday, ending the extremist group’s ambitions for a caliphate on the southern shores of the Mediterranean.

“The battle is finally over,” said Reda Eissa, a spokesman for the coalition of militias from nearby Misurata that led the assault. “Our fighters are ecstatic. We still have to comb through the city and make sure we got them all, but we are so, so happy.”

The Libyan fighters’ apparent success was another defeat for the Islamic State, also known as ISIS or ISIL, as its plans for a militant empire buckle on multiple fronts across the Middle East. In Surt, the Misuratan militias finally ousted the remaining Islamic State fighters from a cluster of houses after a grueling six-month assault that pitted suicide bombers and snipers against Libyan forces backed by American warplanes.

After moving into Surt in 2014, the Islamic State seized a 150-mile stretch of coastline and instituted a brutal reign that included public killings and the imprisonment of migrants as sex slaves. The city became a transit hub for fighters traveling to Tunisia, as well as a supply stop and medical treatment center for Islamists fighting in eastern Libya.