Two other people were also killed, the military said.
The gunmen attacked the building, which is in a high security zone that also houses the head offices of many private banks, with grenades and guns, Karachi police chief Ghulam Nabi Memon told Reuters.
"Four attackers have been killed, they had come in a silver Corolla car," Memon said.
There was no immediate claim of responsibility. Pakistan has long been plagued by Islamist militant violence but attacks have become less frequent in recent years.
The gunmen initially threw a grenade then opened fire on a security post outside the building. The four were killed when security forces posted there responded.
"The situation is still unfolding and management, with the help of security forces, is managing the security and controlling the situation," the Pakistan Stock Exchange (PSX) said on Twitter.