DHAKA - Bangladesh security forces killed three militants on Saturday, including a Bangladesh-born Canadian citizen accused of masterminding an attack on a cafe in Dhaka last month that killed 22 people, mostly foreigners, police said.

The militants were cornered in a hideout on the outskirts of the capital and, having refused to surrender, were killed in the ensuing gunbattle, Monirul Islam, the head of the Dhaka police counterterrorism unit, told Reuters.

He initially said four militants had been killed but later revised the number to three.

US Secretary of State John Kerry is due to visit on Monday to discuss security after a series of killings targeting liberals and religious minorities in the country.

Islamic State claimed responsibility for the assault on the cafe in a posh neighbourhood where militants singled out non-Muslims and foreigners, killing Italians, Japanese, an American and an Indian.

The government has consistently denied the presence in the country of any transnational militant organisation such as Al-Qaeda or Islamic State.

But police believe that Jamaat-ul-Mujahideen Bangladesh, which has pledged allegiance to Islamic State, was involved in organising the cafe attack.

The scale of that attack and the targeting of foreigners has cast a shadow over foreign investment in the poor South Asian economy, whose $28 billion garments export industry is the world's second largest.

"This operation definitely will uphold confidence and the image of Bangladesh," said Bangladesh's prime minister Sheikh Hasina.

She told a news conference: "With this killing (Tamim) one curse has been removed from our shoulders."

The suspected mastermind killed in Saturday's raid was identified as Tamim Ahmed Chowdhury, a 30-year-old Canadian citizen born in Bangladesh. Analysts say Islamic State in April identified Chowdhury as its national commander.

"According to our evidence we are now sure that Tamim was among the three killed," Home Minister Asaduzzaman Khan told reporters. "So the chapter of Tamim has ended here."

Khan said Chowdhury was one of the main suppliers of funds and arms for several recent attacks. He had returned to Bangladesh in October 2013 via Abu Dhabi, AKM Shahidul Hoque, inspector general of police, said.

The raid followed a tip-off from the landlord of the house where the militants were staying, Hoque told reporters. The landlord said the militants had described themselves as businessmen in the medical trade.

Police spokesman Masudur Rahman said the fingerprints of two associates of Tamim who were also killed on Saturday have been sent to the election commission to confirm their identity.

"Police collected evidence from the house though they (the associates) destroyed a laptop and some other documents," he told Reuters.

They rented the house earlier this month and police recovered several grenades, arms and bullets.

Last month police offered a 2 million taka ($26,000) reward for information enabling them to detain Tamim.

Police have also detained two men who had been among the survivors of the restaurant attack.

Hasnat Karim, who holds dual British and Bangladeshi citizenship, and Tahmid Hasib Khan, a student of Toronto University, had been dining separately in the restaurant.

A lawyer for Karim, a 47-year-old engineer, has said his client is innocent. Relatives of Khan, 22, say he is innocent too.

Earlier this month, security forces arrested four women suspected of being members of Jamaat-ul-Mujahideen Bangladesh.