General Hifter initially portrayed himself as battling against political Islam in all its forms. But he has also struck alliances with certain Saudi-style ultraconservative Islamist militias as well, muddying any sense of a battle between secular and religious forces.

Now, beginning on Thursday, his forces have launched a similar campaign aimed at capturing Tripoli. The city has been under the ostensible rule of a powerless United Nations-sponsored unity government and under the practical control of various autonomous militias. Many are also engaged in extortion, migrant smuggling and other criminal activities, and some have had ties to powerful regional militias in the cities of Zintan and Misrata.

With those forces now forming a loose alliance to stop General Hifter, Tripoli residents raced to stock up on food and fuel in anticipation of a prolonged struggle. Lines outside fuel stations stretched for 100 yards, and drivers often waited more than an hour and a half to fill up their tanks.

There were reports of scattered fighting in several places outside the city on Friday. But unusually heavy rain on Friday afternoon flooded streets and slowed troop movements.

In the most significant shift in the battle lines, General Hifter’s forces announced that they had occupied Tripoli’s defunct international airport, destroyed by fighting in 2014. One resident confirmed in a telephone interview that General Hifter’s troops had taken the area, which is less than 30 miles from the central square of the city.

But some local militia members appeared to be massing for an attempt to recapture the area. By the end of the night the interior minister of the United Nations-backed government said on television that it had been retaken already. Flat and open terrain makes it difficult to defend, and the airport changed hands often in battles over the past eight years.

“This is going to be slow,” said Emad Badi, a London-based Libya scholar who is tracking the fighting. “We are going to see more shifting alliances, and any location you control, you might not control it for more than day,” he said, recalling the capture of General Hifter’s forces at Zawiya.