The suspected mastermind of an Isis attack that killed more than 20 people at a café in Bangladesh has been shot dead by police.

Tamim Chowdhury, a Bangladeshi-Canadian militant, died in a gun battle after security forces raided a building near Dhaka on Saturday.

AKM Shahidul Hoque, head of the national police, said he was killed alongside two unidentified men in Narayanganj.

Bangladeshi police guard a house following the raid in Narayanganj (EPA)

Officers raided the house acting on a tip that it was hideout used by Chowdhury and other militants, he said.

The suspects opened fire at police, who retaliated and shot the men dead after they failed to surrender.

Bangladeshi authorities previously named Chowdhury as the mastermind of café attack and a bombing and shooting massacre that targeted people gathering for Eid prayers six days later.

Police identified him as the head of Jamaat-ul-Mujahideen Bangladesh, an Islamist militant group, but Chowdhury has appeared in Isis propaganda as the leader of the terrorist group’s faction in the country.

The so-called Islamic State claimed responsibility for the Dhaka café attack following a series of machete attacks and assassinations, but the government has denied the group has a presence in the country and blamed the atrocity on local organisations.

Officers inspect the house where police say they found Chowdhury (AP)

Five militants armed with guns and knives stormed into the Holey Artisan Bakery and took diners hostage on 1 July, forcing them to recite parts of the Quran to be spared and killing anyone who could not.

Nine Italians, seven Japanese people including a pregnant woman, an Indian teenager, American student and several Bangladeshis were murdered in the 10-hour siege.

Police admitted mistakenly shooting the pizza chef dead as they stormed the building, initially saying six attackers had been killed but later revising the number to five.

Isis published photos of the gunmen through its propaganda agencies, showing them dressed in black with Arab-style headscarves, smiling with assault rifles in front of the group’s black flag.

The group has been prominently advertising its expansion into Bangladesh, featuring an interview believed to be with Chowdhury in the April edition of its English language magazine.

In pictures: Bangladesh attacks Show all 10 1 /10 In pictures: Bangladesh attacks In pictures: Bangladesh attacks Bangladesh attacks Hindu ashram worker Nityaranjan Pande, 62, was hacked to death in Pabna on 10 June 2016 AP In pictures: Bangladesh attacks Bangladesh attacks Hindu priest Anando Gopal Ganguly, left, was murdered in Jhenidah in Bangladesh on 7 June 2016 EPA In pictures: Bangladesh attacks Bangladesh attacks Mahmuda Khanam Mitu, wife of the Deputy Commissioner of Chittagong Metropolitan Police, was murdered in Chittagong, Bangladesh on 5 June 2016 EPA In pictures: Bangladesh attacks Bangladesh attacks Bangladesh Students Union arranged a torch procession in protest over recent murders of free thinkers in Dhaka NurPhoto In pictures: Bangladesh attacks Bangladesh attacks Murdered gay rights activist Xulhaz Mannan, who was editor at Bangladesh’s only LGBT magazine Rex In pictures: Bangladesh attacks Bangladesh attacks A Bangladeshi policeman stands guard at the site of the murder of a law student, hacked to death by four assailants the night before, in Dhaka on April 7, 2016 AFP/Getty In pictures: Bangladesh attacks Bangladesh attacks People have protested against the murders around the world, seen here in Kolkata AFP/Getty Images In pictures: Bangladesh attacks Bangladesh attacks A relative of dead Bangladeshi blogger Washiqur Rahman reacts after seeing his body at Dhaka Medical College in Dhaka on March 30 AFP/Getty Images In pictures: Bangladesh attacks Bangladesh attacks People gather on the spot where Bangladeshi blogger Avijit Roy was killed in a street in Dhaka (EPA) EPA In pictures: Bangladesh attacks Bangladesh attacks Bangladeshi social activists shout slogans during a protest against the killing Avijit Roy in Dhaka on February 27, 2015 AFP/Getty Images

Hailed as the “emir” of the faction under the war name Shaykh Abu Ibrahim al-Hanif, Chowdhury vowed to target Shia and Ahmadi Muslims, “crusaders”, Hindus and missionaries.

“We let our actions do the talking,” he was quoted as saying. “Our soldiers are presently sharpening their knives to slaughter the atheists, the mockers of the Prophet and every other apostate in the region.”

Criticising the Jamaat-e-Islami group blamed for previous terror attacks, Chowdhury made no mention of Jamaat-ul-Mujahideen Bangladesh.

Isis is believed to have drawn much of its local membership from the group, which has been praised in propaganda but made no known pledge of allegiance.

Chowdhury, believed to be around 30 years old, was born in Bangladesh but grew up in Canada.

Bangladesh attack raises security questions

He lived in Ontario with his family and completed a chemistry degree at the University of Windsor but left Canada in 2013 in a suspected attempt to travel to Syria.

Several suspects have been arrested in connection with the café attack, including a British-Bangladeshi man who has been imprisoned without charge for almost two months.

Hasnat Karim’s family say militants forced the father-of-two to act as a human shield during the siege of the Holey Artisan Bakery, where he had been celebrating his daughter’s 13th birthday.

But Bangladeshi authorities suspect him of colluding with jihadists and refused to release him, despite accusations of “arbitrary detention” and human rights violations by lawyers.

No charges have been brought in a series of court appearances and a judge refused another bail application on Wednesday, leaving the 47-year-old detained without access to a lawyer or visitation rights for his family.