Dhaka: As many as eight militants have blown themselves up with a grenade north of the Bangladeshi capital rather than surrender to officers who had cornered them in their hideout, police said on Thursday.

Police urged the militants in Nasirpur, northeast of the capital Dhaka, to give themselves up on Wednesday, but instead they detonated the grenade.

"Up to eight militants, including a female, were killed," Monirul Islam, the chief of police for counter-terrorism and transnational crime, told reporters.

On Monday, Bangladesh army commandos killed four Islamist militants in the northeastern city of Sylhet during a raid on a building where they were holed up.

On Saturday, six people, including two police, were killed and more than 40 wounded in two bomb blasts near the militant hideout in the Sylhet building.

Islamic State claimed responsibility "for a bombing on Bangladeshi forces in Sylhet", the SITE monitoring service said, citing a report on the militant group`s news agency Amaq that appeared to refer to that incident.

Islamic State and al Qaeda have made competing claims over killings of foreigners, liberals and members of religious minorities in Bangladesh, a mostly Muslim country of 160 million people.

The government has consistently ruled out the presence of such groups, blaming domestic militants instead.

Marcia Bernicat, the United States ambassador in Bangladesh, said in a radio interview the police had done "such an excellent job" in identifying hideouts and seizing militants` explosives and money.

"But the other part of the battle is the harder one," she the Radio Today station. "Our real challenge is in helping to prevent people from becoming radicalised and violent in the first place."

She said vulnerable youths needed to be helped, including being given "a proper understanding of religion", so that "they can work to make the world better rather than turning to such violent alternatives."