A policeman from Tamil Nadu was injured when the militants opened fire. Unconfirmed reports said an inspector of the Tamil Nadu Police died in the firing.
Tamil Nadu Police were targeted during searches in a residential area in Puttur town, 30 km from the temple town of Tirupati and close to the Tamil Nadu border.
One of the militants, who was injured in the commando operation, was taken to a local hospital while the other was shifted to Chennai by Tamil Nadu Police. They are suspected to be Bilal and Munna of Al-Umar terror outfit, police sources said.
According to locals in Puttur, the militants had taken the house on rent about a month ago.
The commandos, including those from Organisation for Counter Terrorists Operations of Andhra Police, surrounded the house where the militants were holed up. Police fired teargas shells to flush out the militants who showed some resistance but finally surrendered.
Tamil Nadu Police had reached the town late Friday to conduct search operations based on the intelligence information. A revolver and two bombs were recovered from a house but the militants fired at the policemen from another house.
A tip off about the hideout emerged during investigations into the murder of Bharatiya Janata Party leader V. Ramesh in Salem and other Hindu leaders in Tamil Nadu.
On Friday, the Tamil Nadu Police arrested Fakruddin, who was wanted for allegedly planting a "pipe bomb" in Madurai when BJP leader L.K. Advani was touring the state.