The INS Sindhuratna was being tested at sea when smoke triggered the automatic closure of hatches.
Seven sailors injured in the incident are recovering in hospital. The vessel returned to port on Thursday morning.
Last year 18 sailors died in one of the navy's worst disasters when a submarine sank after a fire at a Mumbai dockyard.
Initial investigations showed arms on board the Russian-built INS Sindhurakshak may have played a role in its sinking.
On Wednesday night Indian navy chief Admiral DK Joshi resigned, accepting "moral responsibility" for this latest incident as well as other operational accidents involving navy ships in recent months.
Lt Commander Kapish Muwal and Lt Manoranjan Kumar died in the INS Sindhuratna incident, the navy confirmed on Thursday.
"The two officers who were earlier declared missing have been located in the compartment of the submarine and after examination by medical officers of the navy hospital, both the officers were declared dead," a defence spokesman in Mumbai, Narendra Vispute, told the BBC.
The vessel was towed back to port on Thursday morning and rescuers boarded the submarine searching for the trapped sailors, a navy spokesman said.
Investigators were assessing the damage to the vessel and trying to find the cause of the smoke, he added.
The navy has appointed a team headed by a senior official to investigate the INS Sindhuratna and earlier submarine accidents.
Wednesday's accident is thought to be the 10th involving a navy warship and the third submarine accident in the last seven months since the Mumbai dockyard disaster in August.
Last month another submarine, the INS Sindhughosh, reportedly carrying ammunition and a full crew, ran aground while returning to the harbour in Mumbai.
There was no loss of life or damage to the submarine.
In February 2010, one sailor was killed when a fire broke out in the battery compartment of INS Sindhurakshak.
Two sailors who went missing after an accident on board a submarine off the coast of Mumbai on Wednesday are dead, India's navy confirms.