Police said at least two of them blew themselves up in 'suicide explosions' and two others were shot by law enforcers.
There was a woman among those killed as police rounded off the 19-hour siege on a two-storey building at Sitakunda Upazila town on Thursday morning.
The identities of those killed are yet to be ascertained and announced.
But intelligence says they belonged to the Jama'at-ul-Mujahideen Bangladesh (JMB), the group responsible for a string of attacks including the attack on an upscale Dhaka restaurant in July last year, when 20 diners, mostly foreigners were killed.
Earlier on Thursday, police said at least two militants died when they set off 'suicide explosions' to thwart a police assault on the building, believed to be a hideout of the banned Islamist outfit JMB.
"So far, we have found four bodies. Two of them were wearing suicide vests and died in the blast and two others died when hit by police bullets. There's no one else inside," police's Chittagong Range Deputy Inspector General (DIG) Shafiqul Islam told the media near the spot around 10am.
He said that three policemen have been injured after grenades were lobbed from inside while a firefighter has been injured while cutting iron grills of windows.
DIG Islam said the raid has ended, but bomb experts were working inside the building.
"We have found a huge amount of explosives in the apartment used by the militants. There were more on the roof. The operation has ended, but the bomb disposal units are working to secure the building."
Police have rescued 20 persons of three families, including women and children, who were stuck in other apartments of the building along with the terrorists during the stand-off since Wednesday afternoon.
"Several attempts were taken to bring them out during the night, but we failed. We once again moved to rescue them after the suicide blast in the morning. They were brought out by breaking the iron grills on the windows," said the senior officer Islam.
The blast was reported after police mounted the assault on the hideout in the morning after sealing-off the building since Wednesday afternoon.
DIG Islam said two terrorists blew themselves up when they found police making their way through the roof of the building.
Around 6 in the morning, police started firing at the hideout when the militants lobbed grenades setting off powerful explosions in quick succession.
Seven to eight minutes of continuous police firing prompted the inmates to retaliate with as many explosions that shook up the area, reports bdnews24.com.
An ambulance could be seen moving out of the compound after police firing and the explosions.
It was not clear whether the ambulance was carrying anyone.
Personnel from the counter-terrorism unit and SWAT joined the RAB and the Chittagong police in the operation on 'Chaya Nir', the two-storey building in Chowdhurypara of Siktakunda town's Premtala area.
Police sealed-off the building after arresting a couple with arms and explosives from another 'hideout' in Sitakunda town on Wednesday afternoon.
When inmates of 'Chaya Nir' lobbed grenades injuring a policeman, the law enforcers encircled the house to ensure no one could escape from there.
Intermittent exchange of fire between security forces and the inmates of the house were reported on several occasions throughout the night.