TRIPOLI, Libya — For the first time since the ouster of Col. Muammar el-Qaddafi in 2011, the independent militias that dominated Libya’s biggest cities and sometimes cowed the central government have fled from the streets, chased away by a combination of civilian protesters and armed groups.

But instead of a triumph for the transitional government of Prime Minister Ali Zeidan, the retreat has marked a new stage in Libya’s descent into chaos. In Tripoli, the capital, the government is now struggling to fill the vacuum left by the sudden disappearance of the militias, which had controlled scores of government facilities and private properties.

In Benghazi, it has been unable to slow an escalating campaign of assassinations and bombings that are believed to be the work of extremist militiamen who have gone underground; now the attacks are targeting the unit that passes for the government’s only security force.

And where it previously relied on the militias to help suppress domestic strife, the government has become helpless against the attempts of rival armed tribes to expand their authority, in several cases by cutting off fuel supplies.

Libyan officials say they still hope the moment offers a chance for the government to take more control. But the formerly dominant militias — the ones in Tripoli identified with major cities, the ones in Benghazi based on Islamist ideology — were at least committed to building a cohesive nation. Now it appears the routed militias may be supplanted by an even more fractious collection of armed groups, including militias representing tribal and clan allegiances that tear at the tenuous sense of common citizenship.

“Libyans feel a stronger sense of belonging to their tribe or their hometown than their loyalty to the central government or the Libyan nation,” said Ali Mohamed Mihirig, the interim minister of electricity, blaming Colonel Qaddafi’s pattern of doling out patronage from the Libyan state as if it had been his private property. “That is why I feel that a lot of Libyans see Libya as, ‘What do I get from government?’ ”

Even as the most prominent militias have gone underground in Tripoli and Benghazi, regions and tribes across Libya have sent their own local militias to cut off oil and gas — the main source of government revenue and the lifeblood of the economy. Berbers in the west are demanding official status for their language, ethnic Tabu tribes in the southern desert insist on more autonomy, and easterners say they deserve a greater cut of the oil wealth and more regional autonomy.

Government officials estimate that the blockades have cost Libya more than $7 billion in lost revenue. The capital is plagued by blackouts and fuel shortages. Motorists wait hours for fuel. Normally crowded highways are nearly empty. Men with Kalashnikovs and truck-mounted artillery stand guard outside gas stations, to deter fights over gas.

The most significant of the blockades is led by Ibrahim Jathran, 33, a commander of an armed group tied to the tribes based around the northeastern city of Ajdabiya. He has cut off all oil flowing out of the region since July and demanded an investigation into what he calls oil-sales corruption and a greater share of the profits paid directly to the East.

With no credible national army — and the dispersal of the big militias that had sometimes acted in its place — the central government has had little coercive power to push back. Mr. Zeidan has issued repeated deadlines and ultimatums that have passed without consequence. (And Mr. Jathran has further humiliated him by appearing on television with $20 million in government checks he said had been offered under the table to restart the oil.)

Government officials have, in fact, empowered the tribes around the country by turning to tribal elders to resolve the blockades. In the case of Mr. Jathran’s blockade, the locally powerful Al Magharba tribe said it had mediated a deal to reopen the ports by last weekend. But Mr. Jathran said in a statement online that he was still holding out until all of his demands were met.

“They are talking to tribal leaders and ‘wise men!’ ” Husni Bey, Libya’s most prominent business mogul, scoffed in an interview. “This is a farce, like they are still thinking they will sit under a tent and decide and talk and have nice kisses on the cheeks and their problems will be swept under the carpet.”

Colonel Qaddafi was a master of such tactics. After abandoning his own early, nationalist attempt to eradicate Libyan tribalism, he switched to cultivating tribal loyalties and pitting tribes against one another. His aim was to prop up his own authority without building the national institutions that might have constrained his peculiar personal power. His ouster promised a more transparent and democratic order, but it also opened a new scramble for advantage among cities, tribes and even Tripoli neighborhoods, as well as Islamist groups.

In Tripoli, the militias began disappearing from the streets after Nov. 15, when a protest outside the base of a militia from the city of Misurata escalated into a shootout that killed 46 civilians, according to a count by Human Rights Watch.

It was in a sense the latest turn in a historic rivalry between the citizens of the capital and the tribes of Misurata. But citywide outrage forced some Misuratans to retreat to their hometown and made others newly responsive to the government. “Now no one is actually saying, ‘No, we aren’t going to give up our arms or leave those places,’ ” said Mr. Mihirig, the minister in charge of their removal.

But Misuratans and militias in Tripoli did not give up their weapons; they only relocated, with some moving underground within Tripoli. The many small neighborhood “brigades” that formed in Tripoli after Colonel Qaddafi fell — armed gangs, really — were a bigger problem, Mr. Mihirig said, calling the smaller, less visible local militias armed “interest groups” led by “warlords.”

And the problem was worse outside the city, where many tribes still have their own militias. “We have got a lot of tribes outside of Tripoli that have heavy weapons that even the Libyan Army does not have,” Mr. Mihirig said, “and if you ask them, ‘Why don’t you give up your arms?’ they say, ‘Our next-door neighbor is having the same things.’ ”

In Benghazi, the challenge centers on the militias that have fled underground and are often ideologically Islamist, including some extremists. The larger, more moderate Islamist militias that supported elections and democracy were routed in clashes with a de facto anti-Islamist alliance of local clans, militias allied with the eastern tribes and a defected army unit known as the “special forces.”

Among the Islamist militias left, the most visible by far was Ansar al-Shariah, a group of extremists that says it opposes democracy and rejects the authority of the interim government. Witnesses have also said some of its fighters participated in the attack on the United States Mission on Sept. 11, 2012, that killed Ambassador J. Christopher Stevens and three other Americans.

Then, in late November, a conflict at a checkpoint escalated into a citywide gun battle pitting Ansar al-Shariah against the government’s Special Forces, which fought with the backing of the eastern tribes and regionalist militias. As many as nine people were reported killed, Ansar al-Shariah’s headquarters was ransacked, and its fighters scattered.

Now the underground fighters who fled Ansar al-Shariah’s base appear to be behind a campaign of daily assassinations and bombings targeting the Special Forces and other security officers.

As the conflict has turned bloodier, more moderate Islamists have spoken out with new explicitness against the extremists as another threat to the fledgling state. “We reject anybody owning weapons outside the government,” including Ansar al-Shariah, said Mohamed Sowane, head of the political party sponsored by the Muslim Brotherhood.

At least one moderate Islamist militia leader who used to swagger around Benghazi turned recently to a tribe for protection.

“You are a man known for killing policemen and army officers, and you also killed the Bedouin,” a member of the Bargathi tribe scolded the militia commander, Ismail el-Salabi, in an online video of the exchange that quickly spread across Libya.

His former military fatigues replaced by a Western-style polo shirt, Mr. Salabi put a hand on a Quran. “I swear to God I have never gotten involved in assassinations, or crimes and betrayals,” he said. “I am a fighter, not a killer,” he repeated three times.