"The militants could have attacked Shia processions in the city today and there is also a possibility they were planning to attack the main Ashura procession" on Sunday, said provincial police chief Chaudhry Muhammad Yaqub.
The militants traded gunfire with police for more than 30 minutes, throwing at least two hand grenades in a bid to break a cordon round their hideout in a congested part of the city overnight, said Deputy Inspector General of Police Rafi Pervez Bhatti.
"One of the militants kept the police engaged in gunfire while the second detonated the explosives," said Bhatti.
Police were trying to identify the dead men.
The militants' hideout was on a road, used by the Shia mourning processions during Muharram, Bhatti said, adding the dead men were suspected of planning to carry out a suicide attack on Muharram processions on Sunday.
A man, who helped them to rent the house there, had been arrested, he said.
The banned Lashkar-e-Jhangvi later said in a statement faxed to newspapers that the militants were its members and that it was proud of their acts.
The group vowed it would carry on attacks against Shias and warned the government not to be happy about killing two of its men.
"Our members were ready to launch suicide attacks and by dying they have provided inspiration to other Lashkar-e-Jhangvi mujahideen and Sunni youth to follow their footsteps," spokesman Commander Zarar said in the message.