CAIRO — Martin Kobler, the United Nations envoy to Libya, used to regularly joke that the only functioning government in Libya was the Islamic State. Unlike the country’s other three governments, it not only held territory but ran the courts, provided services to the public and ensured security — however harsh its rule.

Fortunately, Mr. Kobler said recently, his joke is now out of date, with the Islamic State reduced to three neighborhoods in the coastal city of Surt, and its headquarters in the hands of militias supporting the new United Nations-backed government. “This is over now,” he said.

The problems of governing Libya, however, are far from over, particularly as its many remaining factions try to figure out what comes next at a potential second round of talks this month, presided over by the United Nations. Surt’s future will loom large in the discussions.

Ever since Libya’s longtime ruler, Col. Muammar el-Qaddafi, was deposed and killed in Surt in 2011, the country has been divided by tribal and militia rivalries. With a population slightly larger than that of Miami, Libya has no clear central government and scant possibility of exploiting its enormous oil reserves, the ninth largest in the world.