The United States military evacuated its small contingent of troops from the Libyan capital on Sunday as rival militias raced to stop the forces of an aspiring strongman, Gen. Khalifa Hifter, from taking control of the city.

Forces under the command of General Hifter made a surprise advance on the outskirts of the capital, Tripoli, on Thursday, setting up a battle with a coalition of armed factions from the region around the city — the grand prize in a chaotic eight-year fight for control after the ouster of the dictator Muammar el-Qaddafi during the Arab Spring revolts.

Tripoli is the northern African country’s financial hub, receiving the income from sales of Libyan oil, housing the central bank and paying the salaries of soldiers and other public employees across the country.

By Sunday morning, both sides had begun attacking from the air, using the small and primitive air forces at their command, but the exact targets and extent of the damage could not be immediately determined.