THE CLAIM that the NATO-backed overthrow of Moammar Gaddafi has produced little but chaos in Libya got a boost on Monday when gunmen briefly took over Tripoli’s international airport, fired a few shots and grounded the international airliners that only recently had begun to arrive. Less well-reported was the follow-up: The dust-up ended in a few hours without fatalities, and the airport was back in business Tuesday. Such is Libya: a country awash in militias and weapons and almost entirely lacking in institutions that nevertheless appears to be taking a couple of steps toward a new democratic order for every step back.

Among the recent steps forward: The interim government registered 90 percent of the country’s eligible voters for what would be the first elections in 60 years; 47 percent of those who signed up were women. Some 4,000 candidates have presented themselves for the election of a 200-member national assembly that will be charged with writing a new constitution, appointing a new interim government and overseeing another election a year from now.

Local elections have already been held in the cities of Benghazi and Misrata. In those big cities and in Tripoli, policemen and the regular army keep order, and daily life has mostly returned to normal. So has the engine of the economy: Oil production has reached 90 percent of its prewar level. The government has recovered more than $100 billion in frozen reserves, giving it ample resources for a population of 6 million people.

That still leaves plenty of dangers. Militias control parts of the country and hold hundreds of prisoners — alleged accomplices of the Qaddafi regime — in detention centers where human rights groups have documented abuses. Fighting among tribes and between Arab and sub-Saharan peoples has destabilized several southern cities. Al-Qaeda is seeking a foothold, and a militant Islamist militia leader, Abdel Hakim Belhadj, has formed one of the larger of the 140 new political parties.

The greatest danger is that the much-promised elections will not take place soon enough. The interim government promised them by June 19; senior officials are now saying they won’t complete the process of vetting candidates and printing ballots by then. Mustafa Abushagur, a deputy prime minister visiting Washington this week, said the vote would be delayed by at least a few days but added that it would be held before the beginning of the Ramadan holiday in late July.

The sooner Libya can stage elections, the sooner it will have authorities with sufficient legitimacy to complete the work of extending the government’s rule, dismantling militias and providing sufficient security to attract foreign investment. Until then, incidents like Monday’s airport takeover can be expected. Yet even now, the evidence is against those who argue that the overthrow of Libya’s dictatorship has produced only another Somalia-like failed state. Said Mr. Abushagur: “This is a country, and there is a central government operating.”