The counterterrorism unit of Dhaka Metropolitan Police (DMP) cordoned off the building at the capital's Ashkona early in the morning.
They laid siege to the building, called out the militants to surrender after evacuating residents. The police did not try to storm the building as militants had a lot of explosives.
"We have wrapped up the operations (raid) this afternoon as two of them (militants), including a woman, were killed and another two women surrendered along with two minor children," an official of the unit said.
"The woman, in a burka, came outside with a child and detonated the explosives tied to her waist," senior counterterrorism officer Sanowar Hossain told the media.
As police approached the building after lobbing tear gas shells, they were fired upon and then heard another explosion as the teenage boy holed up inside blew up his suicide vest.
A minor girl, who suffered minor injuries when the woman killed herself, has been taken to the hospital.
An official familiar with the raid said the slain boy was the son of a fugitive leader of Neo-Jamaatul Mujahideen Bangladesh (neo-JMB) while the woman was the wife of another kingpin of the outfit.
"The inmates have vowed to fight us with grenades... we are repeatedly asking them to give up," Dhaka's police commissioner Asaduzzaman Mian earlier told reporters.
Neo-JMB was behind the July 1 terror attack on the Dhaka cafe in which 22 people, including 17 foreigners, were killed.
Sounds of several explosions and gunshots were heard in the areas since afternoon. Law enforcers lobbed several rounds of tear gas canisters targeting the building after the blast, reports our staff correspondent covering the raid from the spot.