On Thursday, his militia said it had taken three towns on the outskirts of Tripoli — Gharyan, 60 miles to the south; Surman, 50 miles to the west; and Aziziya, 25 miles to the southwest.

News reports indicated that there had been only minor violence, and it was unclear to what extent General Hifter had struck bargains with local authorities to allow his troops to enter, or to what extent he fully controlled those towns.

Libya has been plunged into chaos since the ouster of the dictator Col. Muammar el-Qaddafi in 2011, with rival cities and militias competing for power. The bedlam has slashed the country’s oil production, drained much of its sovereign wealth, offered havens to Islamist militants and turned its long Mediterranean coast into a major point of departure for African and Middle Eastern migrants fleeing to Europe.

After announcing in 2014 that he intended to unify the country under his rule, General Hifter, a former officer in Colonel Qaddafi’s army and a onetime client of the C.I.A., struggled for the next three years to wrest the city of Benghazi from the domination of Islamist militias. He received extensive support from Egypt and the United Arab Emirates, who were joined later by France and to a limited extent Russia, and he eventually established his control over much of the eastern region of the country.

His surprise thrust on Thursday appeared to be a gamble that he could now seize control.

Analysts said his advance amounted to a bet that, in part by creating an aura of inevitability about his emergence as Libya’s next strongman, he could strike deals with local armed groups around Tripoli to co-opt them, as he has done successfully in other regions.

But so far his advance has had the immediate effect of uniting many previously disparate regional militias around Tripoli against him.