In the last week of his life, Ambassador J. Christopher Stevens was focused on a problem that has bedeviled Libya since the overthrow of Moammar Gaddafi last year: the countless militias that operate above the law.

Despite the formation of a new government and successful elections this summer, many of Libya’s streets are still run by former rebel fighters who have not fallen under the command of a central authority.

It remains unclear who was behind the attack on the U.S. Consulate in Benghazi on Tuesday that killed Stevens and three other Americans. But the extent of the lawlessness that pervades Libya was certainly a factor.

Stevens, who became ambassador in May, had been talking with friends and colleagues about solutions. According to a friend who attended meetings in Benghazi with Stevens on Monday and Tuesday, the diplomat had proposed sending militia leaders to the United States in an exchange program that would allow them to meet American Muslims and learn about U.S. democracy. The friend, who dropped Stevens off at the diplomatic compound just hours before he died, spoke on the condition of anonymity out of concerns about personal safety.

Libyan authorities said Thursday that they had made four arrests in connection with the attack, but they provided no other details.

In acknowledging Libya’s security shortcomings, the country’s deputy U.N. ambassador, Ibrahim Dabbashi, said Wednesday: “We have to say the reality — that the authority of the government is still not covering the whole territory of Libya, and there are some groups and persons who are outlaws, and the government could not at this moment contain all of them.”

More than 200 private militias are still active in the sprawling North African country, despite efforts by the country’s nascent democratic leadership to draw them into more centralized units, according to a study released this week by the Atlantic Council.

Many of the militias control swaths of territory and huge weapons arsenals looted from Gaddafi’s military bases, according to the study. The stockpile includes tanks, antiaircraft guns and rocket launchers of the type that hit the U.S. Consulate, and about a dozen of the militias are able to project significant military power.

Particularly worrying to U.S. intelligence officials is the possibility that the groups have acquired the far more lethal man-operated portable air defense systems, or MANPADs, which are capable of taking down an airplane. A senior Obama administration official, speaking on the condition of anonymity because the project is sensitive, said U.S. intelligence estimates that 100 to 1,000 MANPADs are still unaccounted for, despite U.S. efforts to buy up and destroy the weapons. Intelligence officials have speculated that the missiles were also smuggled across Libya’s borders.

Glen Doherty, a former Navy SEAL and one of the Americans killed in Tuesday’s attack, told ABC News last month that he had gone into Libya to track down MANPADs as a contractor for the State Department.

Intelligence officials said they have not yet found evidence of the Gaddafi regime’s MANPADs falling into the hands of terrorist organizations.

A Gallup poll conducted in the spring and released Thursday found that 95 percent of Libyans surveyed wanted the militias to hand over their weapons to the authorities right away. But some analysts say the government has appeared nervous about pressing the militias to surrender their arms. “I think the state wants to avoid a confrontation, which could be potentially destabilizing,” said Geoff D. Porter, founder and managing director of the North Africa Risk Consulting firm.

A weak central government has also allowed for the proliferation of radical Islamist cells, Karim Mezran, co-author of the Atlantic Council study, said Thursday.

Some observers have accused Ansar al-Sharia, a shadowy Islamist extremist group in Libya, of being behind Tuesday’s attack.

But according to the SITE monitoring service, the brigade denied any role in the attack, saying in a posting on its Facebook page Wednesday that the accusations against it had been made to damage its image.

Some Libyan analysts and officials tried to play down the strength of armed Islamist radicals in the country.

“These groups are completely isolated, but they are powerful by their influence, not their numbers,” said Noman Benotman, a former member of the Libyan Islamic Fighting Group who is president of Quilliam, a London-based think tank. “The question is, to what extent they are capable of changing agendas.”

In August 2011, four months after his arrival in Benghazi as the U.S. envoy to the rebel administration in Libya, Stevens was already talking about militias. In an address to the State Department, he said that despite progress in the fight against Gaddafi, there was a security “vacuum” and a situation in eastern Libya that involved “a lot of militias and a few police.”

In an interview with The Washington Post in June, Stevens remained concerned and said Libyan authorities were handling the militants in their own way. “The Libyans are well aware of the problem, and they are devising Libyan ways to deal with it.”

Doug Frantz and Tara Bahrampour in Washington and Michael Birnbaum in Cairo contributed to this report.