A senior officer of the Border Security Force, K Srinivasan, said the operation had ended against the heavily armed fighters, who launched an attack in the early morning on an Indian army patrol before holing up in a building on a hill overlooking the cricket stadium.
Both the fighters were killed in the operation, in which two Indian soldiers and a civilian were also injured.
The attack in Indian-administered Kashmir's summer capital Srinagar on Wednesday occurred just hours before Singh arrived in the disputed region.
And it happened despite blanket security in Srinagar for the past two days during which paramilitary and army soldiers and police set up roadblocks, searched cars and frisked pedestrians before Singh's first visit to Kashmir since taking office in May.
It also came on the day India was set to withdraw some troops from the Himalayan territory.
A police officer said the firefight began as soldiers surrounded a rundown building after a tip-off that two fighters had entered late on Tuesday. The building, a former hotel, overlooks the stadium.
The Indian PM (L) announced a
$3.5 billion revival package
Television footage showed soldiers crouching behind armoured jeeps near the site as more troops arrived.
Hundreds of soldiers were on the streets of Srinagar and snipers were on rooftops before Singh's arrival.
Later, in an address to thousands gathered at the cricket stadium, Singh announced $5.3 billion in "economic revival plan".
As the crowd chanted "Give us jobs before peace", Singh said at least 24,000 jobs would be created, adding "a war has to be fought against unemployment".
"New houses, new schools, new hospitals, new railway lines and more power needs to be generated; more phone connections, better irrigation has to be provided," Singh said on his first visit to the Himalayan valley since taking office in May.
Singh earlier told students that "I have a dream and firm belief that we can and we shall build a new Kashmir ..."
New Delhi was on Wednesday to begin a phased withdrawal of some troops from Kashmir which Pakistan also claims.
The disputed territory has been the cause of two of the three wars between the neighbours since independence from British colonial rule in 1947.
The Indian PM has announced a
cut in troop strength in Kashmir
Singh announced the unprecedented cut in troops this month, citing a reduction in an infiltration of fighters from the Pakistani part of Kashmir.
Islamabad has welcomed the move, which analysts say has breathed new life into a sluggish peace process between the old foes, who agreed to a truce along the ceasefire line that divides Kashmir last year after coming to the brink of war in 2002.
But the main alliance of Kashmiri separatist politicians ruled out meeting the prime minister, and a faction of the alliance has called for a day-long general strike on Wednesday, demanding that Singh should apologise for what it said were atrocities committed by Indian soldiers.
"We have nothing personal against Manmohan Singh. But he is visiting Kashmir as the head of a country whose forces are brutalising Kashmir," said separatist leader Sayid Ali Shah Jilani.
"If Manmohan Singh is a man with a good heart, he should on behalf of the country apologise to Kashmiris for the excesses of the Indian forces," he said.
New Delhi-based Colonel Anil Shorey said on Tuesday the pullout would start on Wednesday, with about 20,000 soldiers leaving Kashmir "in a phased manner".
"It is to be seen whether the PM will come with a financial package or a political package. If it is just a financial package we won't have anything to do with it"
Maulana Abbas Ansari,
All Parties Hurriyat Conference
India has never said how many troops are posted in Kashmir. Newspapers have put the number at up to half a million.
Kashmiri separatist groups and local business leaders said Singh would need to do much more than try to buy peace by offering financial incentives.
"It is to be seen whether the PM will come with a financial package or a political package. If it is just a financial package, we won't have anything to do with it," Maulana Abbas Ansari, a senior leader of the All Parties Hurriyat Conference, Kashmir's main political separatist alliance, said.
He said Singh should allow representatives of Kashmiris to join peace talks between India and Pakistan, make it easier for divided families in Indian and Pakistani Kashmir to meet, and prevent rights abuses by Indian forces.
Hurriyat leaders also want to be allowed to visit Pakistan and hold talks with Islamabad before resuming peace talks with New Delhi.
Singh's trip comes before his meeting next week in New Delhi with Pakistani Prime Minister Shaukat Aziz.