TUNIS — Libya’s prime minister, Ali Zeidan, was hauled from his bed at 2:30 a.m. Thursday by a group of militiamen who stormed into the luxury hotel where he lives in downtown Tripoli, a kidnapping that would be extraordinary by almost any standard.

But this was Libya, where militias have unrivaled authority.

A few days earlier, a group of armed men barged into Mr. Zeidan’s office to demand back pay. They refused to leave for hours and ransacked an office when they did leave. Other militias have hampered production of oil, shut down the water running to the capital, forced power cuts, and participated in gunrunning and drug trafficking — all with impunity.

Two years after the fall of Col. Muammar el-Qaddafi, the long-reigning dictator, an air of revolution still hangs over the streets of the nation’s capital, Tripoli, as a weak state struggles to build any sense of national unity, let alone control the unruly, heavily armed militias. It initially seemed that the gunmen may have grabbed the prime minister because they were angry over Washington’s claim that his government approved a commando raid to capture a Libyan citizen suspected of links to Al Qaeda and terrorist attacks.

But these same militiamen had been pressing the government for the prime minister’s resignation, and thus many in Tripoli believe the commando raid was simply a pretense. When he was freed unharmed a short time later, Mr. Zeidan demonstrated just how vulnerable the central government is, thanking the “true revolutionaries” who worked for his release and appealing to armed groups to help build the state.