Police in Bangladesh have killed nine terrorists who they believed were plotting a major attack.

Officers said the militants, holed up in a building in Kalyanpur on the outskirts of the capital Dhaka, opened fire on the police as they tried to enter.

The militants, who shouted 'Allahu akbar' or 'God is greatest' as they battled police, were believed to be members of the Jamaat-ul-Mujahideen Bangladesh (JMB), a banned group that has pledged allegiance to Islamic State.

Police in Bangladesh have killed nine terrorists who they believed were plotting a major attack

Officers said the militants, holed up in a building in Kalyanpur on the outskirts of the capital, Dhaka, opened fire on the police as they tried to enter

They are believed to have been plotting an attack similar to the one on a cafe on July 1 that killed 22 people.

'They were wearing black outfits, turbans and had backpacks similar to the outfits the attackers in the cafe had,' police chief Shahidul Hoque said.

'They were plotting a major attack in the capital like that in the restaurant.'

One wounded militant was captured and another managed to escape, he added.

Prompt action spared Bangladesh from an attack, Prime Minister Sheikh Hasina said.

'They were preparing to carry out a terror attack,' she added. 'Our forces conducted the operation successfully upon getting intelligence reports.'

Islamic State claimed responsibility for the cafe assault, one of the worst militant attacks Bangladesh has ever experienced, but the government has dismissed suggestions the group has a presence there.

The militants, who shouted 'Allahu akbar' or 'God is greatest' as they battled police, were believed to be members of the Jamaat-ul-Mujahideen Bangladesh (JMB), a banned group that has pledged allegiance to Islamic State

The militants are believed to have been plotting an attack similar to the one on a cafe on July 1 that killed 22 people. Pictured: Residents watch the raid

Police said JMB was behind the attack by five young Bangladeshis on the upmarket cafe. Most of the 22 killed were foreigners and the five attackers were also killed.

'The militant who was detained claimed they were Islamic State members, but we think they're JMB,' Hoque said.

Dhaka city police chief Asaduzzaman Mia said police were questioning the owner of the building, from which they had seized 13 grenades and a huge quantity of explosive gel, among other weapons, ranging from pistols to commando knives.

'The militants were wearing black outfits, turbans and had backpacks similar to the outfits the attackers in the cafe had,' police chief Shahidul Hoque said

Over the past year, Al Qaeda and Islamic State have made competing claims over a series of killings of liberals and members of religious minorities in the mostly Muslim nation of 160 million people.

While authorities have blamed the violence on domestic militants, security experts say the scale and sophistication of the assault on the cafe suggested links to a trans-national network.