The hour-long raid was launched at 5:51 AM (local time) at Jahaz building in Kalyanpur area by special police units.
The militants, aged between 20 and 25 and suspected to be members of Jamatul Mujahideen Bangladesh (JMB), opened fire on police during the operation.
"From police intelligence sources we learnt that they were planning to carry out a major incident. We conducted the operation to foil any such incident," national police chief A K M Shahidul Hoque told reporters.
The Islamist gunmen wearing black tunics exchanged fire intermittently throughout the night and shouted "Allahu Akbar" (God is the Greatest).
More From This Section
Two more presumed extremists, including one with bullet wounds, were arrested from the scene, he added.
Rakibul Hasan alias Rigan, a militant activist who sustained bullet injuries during the operation, was missing since last one year. He claimed to be a member of the Islamic State, reports said.
Police recovered 13 handmade grenades, one sword, one pistol, seven magazines and bullets from the den
Hasina praised the law-enforcers, saying, "Police have conducted the operation successfully. It was clear that they were fully prepared for a terror attack."
"The country averted a fearful situation because of the raid."
Bangladesh is reeling under a wave of deadly attacks by Islamist extremists.
Twenty two people, mostly foreigners including an Indian girl, were killed by suspected ISIS militants inside a cafe popular with expats in the diplomatic zone in Dhaka in the worst terror attack in Bangladesh before commandos launched an assault, killing six attackers and capturing one alive.
The government, however, maintains that the home grown militant outfit Jamaat-ul-Mujahideen (JMB) was behind the attack.
Days after the cafe siege, gunmen attacked the country's largest Eid prayer gathering, killing at least three people.