British Prime Minister David Cameron pledged to help Libya's police and army Thursday as he made an unannounced visit to the North African country's capital, Tripoli.

Cameron -- fresh off a visit to Algeria, where he struck a security partnership -- said Britain was prepared to provide training and advice to Libya amid growing concerns over security in the region.

His office said Cameron will hold bilateral talks in Libya and discuss how Britain can help build a "strong, prosperous, democratic" Libya. The talks will explore what support and expertise the U.K. can offer to strengthen security and defeat terrorism, the British government added.

Cameron's visit to the Libyan capital comes just days after Britain's Foreign Office warned of a potential threat against the U.K. embassy in Tripoli.

Just before that, the Foreign Office joined other governments in urging their citizens in Benghazi, Libya's second largest city, to evacuate in response to what was described as an imminent threat to Westerners.

The Foreign Office on Thursday would not comment on the status of those threats but said it was "taking appropriate measures."

Locals greeted Cameron as he toured Tripoli's famous Martyrs Square amid tight security.

Cameron also visited a police training center on the outskirts of the capital, telling police recruits it was "very good to be back." He last visited Libya in September 2011.

"I will never forget the scenes I saw in Tripoli and Benghazi," he said, according to Britain's Press Association. "The British people want to stand with you and help you deliver the greater security that Libya needs. So we have offered training and support from our police and our military."

The prime minister is later expected to travel to Liberia for a development conference.