Police raided the building in the southern port city of Chittagong late Wednesday, sparking a 15-hour stand-off with terrorists armed with guns and grenades during which around 20 civilians were trapped inside.
On Thursday, National Police Chief A.K.M Shahidul Hoque declared the operation over and said four members of the homegrown terrorist group Jamayetul Mujahideen Bangladesh (JMB) had died.
At least two of them were killed in a suicide explosion, said Sanwar Hossain, additional deputy commissioner of the police counter-terrorism unit.
"They came out in the stairs and carried out a big explosion. Parts of their bodies were spread to 25-30 yards (metres)," Mr Hossain said.
Another 20 people who were trapped inside the building overnight after police cordoned off the place were taken out safely, police officials have said.
Two police officers were injured in the operation.
"The extremists threw at least 10 grenades at our officers. They were staying in one of the ground floor flats in the building," Additional Superintendent of Police Mosiuddowla Reza told AFP.
"They also opened fire at us with pistols."
Elite counter-terrorism police reinforcements were sent to the area from the capital after midnight to storm the compound, he said.
Bangladesh has suffered a spate of deadly attacks on secular activists, foreigners and religious minorities in recent years.
They have blamed the JMB for the attacks, including a siege at a Dhaka cafe in which 22 people including 18 foreign hostages were killed.
Security forces launched a crackdown on terrorists following the siege, arresting scores of suspected terrorists and killing several top leaders of homegrown terrorist cells.
This month they have carried out a series of raids as part of a major security crackdown in the Chittagong region after detaining two terrorists with grenades earlier this month on the Dhaka-Chittagong highway.
On Wednesday, police also raided a second suspected hideout in the area where they arrested two people who they said were JMB members.
One tried to blow herself up before she was taken into custody, Mr Reza told AFP.
"We arrested them as the wife was holding her three-month-old child in one hand and tried to explode the suicide vest with the other," he said.
"Our bomb disposal unit later defused the vest."
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)
Get Breaking news, live coverage, and Latest News from India and around the world on NDTV.com. Catch all the Live TV action on NDTV 24x7 and NDTV India. Like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.