Two top Islamist militants, from the US and UK, have been killed in Somalia after falling out with al-Shabab, witnesses have told the BBC.

Omar Hammami, known as al-Amriki, and Osama al-Britani, a British citizen of Pakistani origin, are said to have died in an early-morning attack in a village south-west of the capital, Mogadishu.

They have been hiding from al-Shabab since leaving the group this year.

There have been several previous reports of al-Amriki's death.

In March, the US State Department offered a $5m (£3.1m) reward for any information leading to the capture or conviction of al-Amriki.

'Quick-witted'

One of al-Amriki's fighters told the BBC that they had been overpowered by the al-Shabab attack in a village near the town of Dinsor.

He said al-Shabab had taken away the bodies of the two Westerners.

Another of their allies, Khadap al-Masari, from Egypt, surrendered, the fighter said.

Local residents confirmed the deaths, as did a senior source within al-Shabab.

"There was a gun battle between al-Amriki and his men and other fighters," Moalim Ali, a resident in Bardhere village, told the AFP news agency.

Another resident, Mohamed Wardhere, said: "Al-Amriki and two other fighters, one of them a foreigner, have been killed near Bardhere."

The two men were allies of veteran Somali Islamist, Sheikh Hassan Dahir Aweys, who split from al-Shabab in June.

He is currently in the custody of the UN-backed government.

BBC Somali analyst Mohamed Mohamed says al-Shabab has been hunting down and killing allies of Mr Aweys since the split.

Mr Aweys is seen as less hardline than al-Shabab leader Ahmed Abdi Godane, who also has a more international agenda.

Al-Amriki was known for rapping jihadist songs which were loaded onto YouTube.

He grew up in the town of Daphne in the state of Alabama, where friends said he was popular at school, quick-witted, charismatic and elected president of his school year.

According to his schoolfriend, James Culveyhouse, his father is a Sunni Muslim from Syria and his mother a Southern Baptist Christian.

Mr Culveyhouse told the BBC in 2011 that al-Amriki's radicalisation started after a visit to Syria as a teenager.

Over the years he became an adherent of stricter and stricter Islam - turning far more orthodox than his father.

He moved to Somalia in 2006 and joined al-Shabab, becoming one of the group's senior officials.

The news of the killings of the foreign militants in Somalia comes a day after a group of 160 leading Islamic scholars issued a fatwa denouncing al-Shabab, saying the group had no place in Islam.

Nairobi-based Somali analyst Mohamed Abdullahi told the BBC's Newsday programme that the fatwa, issued by so many prominent scholars, is likely to sway opinions on the ground, but is unlikely to change the path of those in the group's top leadership.

"[It says] you cannot give them sanctuary, you cannot support them, you have to report their presence and you have to assist international security agencies so the fatwa includes a security element of community policing against al-Shabab," he said.

But it should be coupled with other efforts to win the hearts and minds of people on the ground, he added.

"There must be another parallel programme to ensure that those young men who joined for economic reasons, for instance, are provided with employment or opportunities."

The edict was announced at the end of a conference on tackling extremism organised by the government of President Hassan Sheikh Mohamud.

He took office a year ago, vowing to end two decades of fighting in the country.

Last week, al-Shabab's Twitter account was suspended for a second time after claiming on its feed that it had ambushed the convoy of the president, who was unhurt.

It has since set up a new account.

Pro-government forces have pushed al-Shabab out of several key cities but the group still controls many smaller towns and rural areas.