An Islamist militia linked to the attack on the U.S. consulate in Benghazi and kicked out of the city by locals is back openly manning checkpoints and building up support promising much-needed security.

Heavily bearded youths from Ansar al-Sharia control the western entrance into Libya's second biggest metropolis, patrol a hospital and check cars and trucks passing through another checkpoint in the south.

Witnesses say the group's members were at the scene of the September 11 attack that killed the U.S. ambassador, Christopher Stevens, and three other Americans - though Ansar al-Sharia denied any involvement.

Days after the assault, outraged residents drove the group out of its bases in the city in a "Rescue Benghazi" protest.

The group's highly visible return, five months on, underlines the complex security situation on the ground two years after the start of the revolt that ousted Muammar Gaddafi.

Many in the West see Islamist militants as the biggest threat to the security of the oil-producing country and the region - and accuse them of carrying out a string of attacks on police and foreigners in the city in recent months.

Their fears echo international concerns about the rise of Islamism in other countries shaken by the Arab Spring uprisings, including Libya's neighbors Egypt and Tunisia.

But the groups are also held up as heroes of the Libyan uprising by some locals who say they are doing a better job of the protecting them than the government in distant Tripoli.

As celebrations began marking the revolt's anniversary, at least one person waved Ansar al-Sharia's white flag at a rally.

"These men are also people who fought on the front lines, care about their city and provide services. We can't shun them," said Benghazi University professor Iman Bugaighis. "We had to ask them to come back and protect our hospital and streets."

Libya's deputy prime minister, Awad Ibrahim, on Sunday acknowledged the security role played by militias, without specifically mentioning Ansar al-Sharia.

"These militias are part of our liberation. We cannot exclude them at least at this time until we build our army and police," he told Reuters in Benghazi, the cradle of the revolt.