Lesotho's Prime Minister Thomas Thabane has accused his country's army of staging a coup against him and fled to neighbouring South Africa, which condemned the military's action and called for a peaceful settlement.

Early morning gunfire was heard in Maseru, capital of the small southern African kingdom encircled by South Africa.

Army units occupied police headquarters and surrounded the prime minister's residence, residents and diplomats said.

Hours after the army's move, the capital was reported to be quiet but it was not immediately clear who was running the government of the mountainous state of two million people.

Mr Thabane, who in June dissolved parliament to avoid a no-confidence vote against him amid feuding in his two-year-old coalition government, said he had crossed over to South Africa because he feared for his safety.

"There was clearly an effort to launch a coup," Mr Thabane told Reuters, saying he was at his daughter's home in South Africa.

"We are taking concrete steps to nip it in the bud," he added, saying the regional Southern African Development Community was addressing the situation.

South Africa, speaking on behalf of SADC, condemned the actions of the Lesotho military, which it said "bear the hallmarks of a coup d'etat". It called on Lesotho's army commander to order his units back to their barracks.

"Any unconstitutional change of government shall not be tolerated," South African Foreign Ministry spokesman Clayson Monyela told a news briefing in Pretoria.

Earlier, giving its version of events, the Lesotho Defence Force denied attempting a coup against Mr Thabane, saying it had moved against police elements suspected of planning to arm a political faction, an army spokesman said.

"There is nothing like that (a coup), the situation has returned to normalcy ... the military has returned to their barracks," Major Ntlele Ntoi told Reuters. He added the military "supports the democratically-elected government of the day".

Mr Ntoi said one soldier and four police had been injured during the army action. At least one witness reported police officers being detained by soldiers.