The shootout ensued after the paramilitary forces raided a safe house in Manghopir area and the gunmen there retaliated by opening fire on the soldiers.
"One soldier was injured in the gunfight while four of those holed up in the safe house were killed," a Rangers spokesman said.
The operation was carried out as part of the ongoing clean-up operation in Karachi and in the Balochistan province.
Meanwhile, last night, at least five militants belonging to the banned Baloch Republican Army, a separatist group, were killed by the Frontier Corps in the Dera Bugti area. Security forces destroyed the camps and hideouts of militants in the area and there was a heavy exchange of fire which went on for several hours.
"The raid took place on the outskirts of Dera Bugti and five militants of the BRA were killed in the operation," a Frontier Corps spokesman said.