The deceased were identified as Zia alias Babul, 30, son of Shamsul Alam; and Azim Ullah, 46, son of Kefayet Ullah of the upazila.
Babul was wanted in several criminal cases, said police.
Pradip Kumar Das, officer-in-charge of Teknaf Model Police Station, said police arrested Babul from Hinla Bazar on Wednesday afternoon.
After interrogation, a team of police took him with them in a drive to recover firearms around 4am.
As soon as police reached the spot, Babul’s associates opened fire and tried to snatch the criminal, the OC said.
Babul and Azim sustained gunshot wounds during the skirmish. They were taken to a local hospital where doctors pronounced them dead.
Four policemen were injured during the gunfight, the OC said.
A shutter gun, five light guns, 36 bullets, and 5,000 Yaba pills were recovered from the spot.